Bluehost.com Web Hosting $6.95

PHP Sockets - How to detect client disconnection?

This is a discussion on PHP Sockets - How to detect client disconnection? within the PHP General forums, part of the PHP Programming Forums category; How do I detect a disconnected client from a socket resource? In an infinite loop, I socket_read() every open resource ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-06-2007
Anthony Rasmussen
 
Posts: n/a
Default PHP Sockets - How to detect client disconnection?


How do I detect a disconnected client from a socket resource?

In an infinite loop, I socket_read() every open resource that passes a socket_select().

As far as I know, the only way to detect if the client disconnected unexpectedly from their socket resource is when socket_read() returns FALSE (which, during my testing, produced the warning: "An established connection was aborted by the software in your host machine.").

However, socket_read() doesn't return FALSE on a disconnected client's socket resource until I first attempt to socket_write() to that resource.

In brief pseudo code...

socket_create(AF_INET, SOCK_STREAM, SOL_TCP)
while (TRUE)
foreach (resource where (false === socket_select($arrayofresources,NULL, NULL, 0, 0))
if (socket_read() === false)
WON'T DETECT DISCONNECT UNTIL I FIRST socket_write()

I appreciate any support you offer and thank you for your time.

Best regards,

-Tony

__________________________________________________ _______________
Type your favorite song.* Get a customized station.* Try MSN Radio powered by Pandora.
http://radio.msn.com
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:10 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0