From: Joel VanderWerf Date: 2004-02-21T11:15:14+09:00 Subject: Re: TCPserver client disconnect Noah wrote: > "Joel VanderWerf" wrote in message > news:4036ACF4.9000007@path.berkeley.edu... > >>Noah wrote: >> >>>ruby newbie question... >>> >>>How can I detect when a client disconnects from a TCPserver? >>>I'm streaming data to the client in a while loop (Shoutcast-style mp3 >>>stream), but I'm not sure what condition to test to see if the client > > drops > >>>out. >> >>Does sample/svr.rb (in the ruby distribution) help? >> > > Not really, because in that example, the server is checking for the client > eof, right? (Correct me if I'm wrong. I just started with Ruby a few days > ago.) > > In my application, the client makes one initial request, and then simply > receives. The server is the only one sending data. It's like a HTTP > request. Imagine a client does a GET on a very large file. The server > begins to send the data, but the client drops out half-way through. How can > the server detect this and cancel the transfer? Errno::ECONNRESET seems to be the exception raised. At least on linux. In samples/svr.rb, I replaced s.write(str) with s.write(str*10_000) and ran samples/clnt.rb as usual. When the client is interrupted, the server receives: svr.rb:27:in `write': Connection reset by peer (Errno::ECONNRESET) from svr.rb:27 from svr.rb:15:in `each' from svr.rb:15 from svr.rb:12:in `loop' from svr.rb:12