0

l have a php script writing to TCP socket.

This connection needs to be always one as it can receive data anytime from the server.

Now problem is only the first instance of socket_write works.

i need to keep reading and writing data to the socket

Just to clarify l have tried to catch the error but no error is returned

Edited by masocha: addtional ifo

2
Contributors
5
Replies
7
Views
5 Years
Discussion Span
Last Post by masocha
0

l am using fsocketopen(), with fread () and fwrite().The script works file for the first run but if l try again the second time it does not work.Looks like data is written successfully but is not getting to the intended recipient

0

l am using fsocketopen(), with fread () and fwrite().The script works file for the first run but if l try again the second time it does not work.Looks like data is written successfully but is not getting to the intended recipient

0

The code is basically as below.

Its quite long so l just put whats neccessary here.

On the first while loop cycle the script works fine.However subsequent callse send data andl get the number of bytes sent but the data does not get to the recipient

$fp = fsockopen($address, $service_port, $errorno = null, $errstr = null, 100);
while ($out = fread($fp, 2048))
        {
 for ($written = 0; $written < strlen($string); $written += $fwrite)
    {
        $fwrite = fwrite($fp, substr($string, $written));

    }
 fflush($fp);
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.