WuT x 2: TCP Echo Server With PHP
Có thể bạn quan tâm
- Our product range
- Web-IO
- Introduction
- Digital 24V
- Digital 230V
- Analog 0-10V/0-20mA
- Web Thermometers
- Time Switch and SIP Ring Switch
- Switching via iCal
- Switching via SIP/:VoIP
- Networking
- IT security / Microwall
- Edge computing
- rule.box / Node-RED
- MQTT broker
- logic.hub
- Node-RED | MQTT | logic.hub
- IP Watcher
- Network memory
- transfer.box
- FTP Data Station
- Industrial Switches
- Single Pair Ethernet (SPE)
- Serial / USB to Ethernet
- Com-Server
- USB Device Server
- transfer.box
- Serial interfaces
- Converters, buffers and switches
- USB for industrial use
- Isolators and Fiber Optics
- PCI, PCI-Express, ISA
- Centronics
- Services
- Software Development
- Hardware Development
- Electronics production (EMS)
- Fulfillment
- Other
- Services
- Accessories
- Other
- Accessories
- Older devices
Application:
TCP Echo Server with PHP More links- Product overview
- Application overview
Running a PHP script when data are received on a TCP port
The pure.box 2 is able to respond when data are received (transmission via TCP or UDP) by opening a PHP script. The received data can be read via PHP and then further processed (e.g. reply to data source, forwarding over the network or saving in the box internal database. The PHP interpreter works here only "under the hood," i.e. no classical output in the form of a web page is generated. This functionality lets you implement simple server applications, using only web technology.
Objective
To test a network connection you want to set up an echo server on the pure.box 2 which listens to TCP port 8000. Data sent to this port will then be returned to the source unchanged.
The PHP file for implementing this example, echo.php, can be downloaded here.
Configuration of the pure.box 2
Save the file echo.php using FTP or SMB sharing in the folder named programs on the pure.box 2. Then carry out the following configuration steps:
-
Open the Homepage of the pure.box 2 by entering the IP address in the address line of your browser.
-
Select Login in the menu tree and log on using your password in the opened dialog box.
-
Navigate to the page Home >> Configuration >> User files. In the file overview click on the folder named programs. The file echo.php is displayed.
-
Clicking on the icon Edit file properties (left next to echo.php) opens the Edit dialog.
-
Check the option Event controlled. Select TCP and set Port to 8000. Save your changes by clicking on Save... you’re done!
Now if data are sent to TCP port 8000 on the pure.box 2, they are returned to the sender. The prerequisite for returning the data is reception of a line break (LF / Return key) as end character. In general it must be noted that running of the PHP interpreter is automatically stopped after two minutes. The programmed action should therefore be executable in less time than this.
Source text
In the first two lines the standard input for reading and the standard output for writing data is opened.
$in = fopen(’php://stdin’, ’r’); $out = fopen(’php://stdout’, ’w’);The incoming data are read character by character in a loop and the string variable $input is appended. The loop is exited when a line break (Line Feed, ASCII table: 10) is detected.
$input = ’’; do { $input .= fread($in, 1); } while(substr($input, -1, 1) != chr(10));After receipt, the read string is sent back out to the initiating data source through the standard output.
fwrite($out, $input);Then both the standard input and standard output are closed.
fclose($in); fclose($out);This PHP script has now been fully run and is exited. The next time data are received the script is restarted and runs again as described above.
Summary
Simple server applications can be implemented with the pure.box 2 just by knowing PHP. The server functionality is already built into the box. All that is left is to program the action you wish to occur when the data are received.
^Từ khóa » E Echo Php
-
PHP Echo And Print Statements - W3Schools
-
PHP Echo() Function - W3Schools
-
Echo - Manual - PHP
-
Echo -e Content Of File Fetched Using Foreach - Stack Overflow
-
PHP Echo And Print - Pi My Life Up
-
How To Use Echo To Print Data In PHP
-
Qual é A Diferença Entre Echo, Print E Print_r Em PHP? - Acervo Lima
-
PHP Echo And Print - GeeksforGeeks
-
Curso De PHP/Comandos/Echo - Wikilivros
-
Diferença Entre Echo E Print Em PHP - Natapa
-
Display All PHP Errors: Basic & Advanced Usage
-
How To Check PHP Version {2 Methods Explained} - PhoenixNAP
-
Home - Twig - The Flexible, Fast, And Secure PHP Template Engine
-
Echo Vs. Print In PHP - Difference And Comparison - Diffen