Saturday, 24 August 2013

Socket wait for read before writing

Socket wait for read before writing

Desire: I want to connect to the socket and have 'running' sent to the
client every second.
This of course is a test.
Issue: The output 'running' is only sent when the client sends data. It
seems like the loop is pausing waiting on the client to write back.
Code:
$socket = @socket_create_listen("12345");
while (true) {
$client = socket_accept($socket);
$msg = "\nHello"."\r\n".chr(0);
$length = strlen($msg);
socket_write($client, $msg,$length);
usleep(5);
while (true) {
$msg = 'running'."\r\n".chr(0);
$length = strlen($msg);
socket_write($client, $msg, $length);
sleep(1);
}
}
I am really not sure what could cause this.
Thanks JT

No comments:

Post a Comment