Hi there Please see the screenshot below. I have a device at ip address 192.168.1.112 that connects and sends data to another device 192.168.1.100:8888. I can see this using a GUI Windows tool that I have (screenshot). What I would like is a php script that connects, binds and listens to 192.168.1.100:8888 and extracts the data heard on that port and enters it into MySQL database. Can anyone help me with a script that will do this please?
What is the format for your data and where is the mysql server hosted ? here only >> 192.168.1.100:8888
MySQL server is at localhost and the data is sent in HEX format. What I would like is to be able to read the data being sent to 192.168.1.100:8888 from 192.168.1.112 To start with, how can I get this to even output in a browser? I have this code, but it just sits there in the browser but doesn't output anything: <?php /* Open a server socket to port 8888 */ $server = stream_socket_server('tcp://192.168.1.100:8888'); /* Accept a connection */ $socket = stream_socket_accept($server); /* Grab a packet (1500 is a typical MTU size) of OOB data */ echo "Received Out-Of-Band: '" . stream_socket_recvfrom($socket, 1500, STREAM_OOB) . "'\n"; /* Take a peek at the normal in-band data, but don't comsume it. */ echo "Data: '" . stream_socket_recvfrom($socket, 1500, STREAM_PEEK) . "'\n"; /* Get the exact same packet again, but remove it from the buffer this time. */ echo "Data: '" . stream_socket_recvfrom($socket, 1500) . "'\n"; /* Close it up */ fclose($socket); fclose($server); ?> Code (markup): I can see that a connection is being established using netstat in windows:
Try something like this: set_time_limit (0); $address ='46.49.41.188'; $port =7777; $con =1; $word =""; $sock = socket_create(AF_INET, SOCK_STREAM,0); $bind = socket_bind($sock, $address, $port); socket_listen($sock); while($con ==1){ $client = socket_accept($sock); $input = socket_read($client,2024); if($input =='exit'){ $close = socket_close($sock); $con =0;} if($con ==1){ $word .= $input;}} echo $word; Code (markup): Source: https://stackoverflow.com/questions/12999900/php-socket-listening-loop/13000206#13000206
This isn't showing anything either, the page just hangs. It establishes the connection OK, as I can see it as 'Established' in 'netstat' but nothing is echoed out to the browser. If I refresh, I just get the error below, which indicates the port is in use: Warning: socket_bind(): unable to bind address [10048]: Only one usage of each socket address (protocol/network address/port) is normally permitted