user1833028
user1833028

Reputation: 943

PHP: stream_socket_server()

I have a homebrew PHP TCP chat server, but it doesn't have a way to detect remote disconnects.

I would be grateful if someone knew a way to just take a stream_socket_server() and spit out everything connected to it.

Then you could run a loop like this, in psuedocode:

$main_socket=stream_socket_server("tcp://",....)

//Do Something.... say, wait for a connection (with stream_socket_accept())?

for (each CONNECTION in $main_socket)
{
//Do something with or to that connection
}

//Loop back... if you need to say, wait for another connection

Alternatively, could I check if a variable created with $stream_socket_accept() is presently connected.

This project is bust until I figure this out. I'd be grateful to anyone who could help me out on this one!

Upvotes: 6

Views: 2267

Answers (1)

Daniel
Daniel

Reputation: 3806

The correct way of knowing if the remote host has disconnected is to test for a false socket_read(), as far as I know.

Have a look at this question; PHP - Detecting remote host disconnection

Upvotes: 1

Related Questions