While (true)
{
//Once every 5 seconds
receive_message (' 127.0.0.1 ', ' 5 ');
}
//Custom function for getting messages
function Receive_message ($i PS Tutorial erver, $portnumber, $nbsecondsidle)
{
//Create socket
$socket =stream_socket_server (' tcp://'. $ipserver. ': ' $portnumber, $errno, $errstr);
if (! $socket)
{
//If the socket failed to create the output content
echo "$errstr ($errno)
n ";
}
Else
{
//Accept socket connection and get information if successful creation
While ( $c/span>))
{
$message =read ($conn, 1024x768);
Echo ' I had received that: '. $message;
fputs ($conn, "okn");
fclose ($conn);
}
fclose ($socket);
}
}
//server End
?>
//The following code is the client, it sends the message and reads the reply
send_message (' 127.0.0.1 ', ' a ', ' message to send ... ');
//Custom function, send message
function Send_message ($ipserver, $portserver, $message)
{
$fp =stream_socket_client ("tcp://$ipserver: $portserver", $errno, $errstr);
if (! $fp)
{
echo "erreur: $errno-$errstr
n ";
}
Else
{
fwrite ($fp, "$messagen");
$response = Fread ($fp, 4);
if ($response! = "OKN")
{
Echo ' The command couldn ' t be executed...ncause: '. $response;
}
Else
{
echo ' execution successfull ... ';
}
fclose ($fp);
}
}
The above describes the use of PHP stream_socket_server and stream_socket_client, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.