Sending string/data via php to device connected to my server
you must write program for socket .see this page for php socket programming http://php.net/manual/en/book.sockets.php
with this function you can connect to every port , send data and get response with every format that you want .
sample:for connect to Device
<?php
$fp = fsockopen("udp://127.0.0.1", 2000, $errno, $errstr);
if (!$fp) {
echo "ERROR: $errno - $errstr<br />\n";
} else {
fwrite($fp, "data for send");
while ( !feof( $fp ) ) {
$ret .= fgets( $fp, 4096 );
}
echo $ret;
fclose($fp);
}
?>
more sample http://php.net/manual/en/function.fsockopen.php
raaj
Updated on June 04, 2022Comments
-
raaj almost 2 years
Good Day,
I have a hardware device (an RN-XV WiFi chip) which has successfully connected to my server IP address through port 80. I am able to send junk data and it responds with a "server is unable to serve this request", meaning there is a connection.
Now, I need to talk to this device/send it data/strings. I know some basic PHP, but I have no idea how to approach this problem. My device is connected to the server but:
To send data to it, I have to know the IP/Port of the device connected right? How do I find that out?
If I am able to obtain this..is sending data a matter of opening a TCP connection via PHP and sending a string?
Now that I am connected to the server, I am somehow able to send strings, but it returns with a server unable to serve this request. How do I actually send data to a particular PHP file to read?
Please Help! Thanks in advance!