zaez Posted January 27, 2009 Share Posted January 27, 2009 Alright i'm running my server on my localip, accesible only for our network. the loop: private function listenToSockets() { while (true) { $changed_sockets = $this->currentSockets; $num_changed_sockets = socket_select($changed_sockets, $write = NULL, $except = NULL, NULL); foreach($changed_sockets as $socket) { if ($socket == $this->masterSocket) { if (($client = socket_accept($this->masterSocket)) < 0) { continue; } else { // NEW CLIENT HAS CONNECTED $this->currentSockets[] = $client; socket_getpeername($client, $newClientAddress); } } else { $bytes = socket_recv($socket, $buffer, 4096, 0); if ($bytes == 0) { // CLIENT HAS DISCONNECTED $index = array_search($socket, $this->currentSockets); // Remove Socket from List unset($this->currentSockets[$index]); $this->game->removePlayer($socket); socket_close($socket); } else { // CLIENT HAS SENT DATA $this->parseRequest($socket, $buffer); } } } } } the client side is AS3, connecting through XMLSocket, and talking to the server using XML data. Well everything works good. The problem is that if i disconnect the client from the network (unpluging the cable, or just disconnecting the wireless connection), this: if ($bytes == 0) { // CLIENT HAS DISCONNECTED $index = array_search($socket, $this->currentSockets); // Remove Socket from List unset($this->currentSockets[$index]); $this->game->removePlayer($socket); socket_close($socket); } won't trigger, as if the socket would be still sending data. So, question: How do i make my server script detect when a client disconnects from the network? Any help, or advices welcome and appreciated. Thank you for looking! Link to comment https://forums.phpfreaks.com/topic/142707-solved-php-socket_server-disconnecting-client-problem/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.