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

How are you using this PHP script then ?

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

How are you running it the second time ? Can you show some code ?

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

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);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.