I have a device which sends data in every 5 seconds using tcp and i am using php socket programming
and my code isn't working this code print nothing and when i use this code without loop(while loop) then it works i want to continue listen the data that my client sends in every 5 seconds please help me out....thanks in advance.
<?php
error_reporting(E_ALL);
set_time_limit (0);
$host = '103.21.XX.XX';
$port = 60000;
$con = 1;
$word = "";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die(socket_strerror(socket_last_error()));
$result = socket_bind($socket, $host, $port) or die(socket_strerror(socket_last_error($socket)));
$result = socket_listen($socket) or die(socket_strerror(socket_last_error($socket)));
while ($con==1) {
# code...
$spawn = socket_accept($socket) or die("Could not accept incoming connection
");
$input = socket_read($spawn, 2048) or die("Could not read input
");
$input=(String)$input;
echo $input;
if ($input == 'exit')
{
$close = socket_close($sock);
$con = 0;
}
if($con == 1)
{
$word .= $input;
}
}
echo $word;
?>