TCPserver client disconnect

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.

Thanks

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?

“Joel VanderWerf” vjoel@PATH.Berkeley.EDU 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?

Noah wrote:

“Joel VanderWerf” vjoel@PATH.Berkeley.EDU 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:ineach’
from svr.rb:15
from svr.rb:12:in `loop’
from svr.rb:12

“Joel VanderWerf” vjoel@PATH.Berkeley.EDU wrote in message
news:4036BF2A.1080606@path.berkeley.edu

Noah wrote:

“Joel VanderWerf” vjoel@PATH.Berkeley.EDU 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:ineach’
from svr.rb:15
from svr.rb:12:in `loop’
from svr.rb:12

Ah, it turns out I was generating that exception, but I couldn’t see it
because it was jumping to an ‘ensure’ block, and I guess the thread would
just die. I moved the s.close into the ensure block and now it’s working
great.

Thanks for the help.

Noah wrote:

Ah, it turns out I was generating that exception, but I couldn’t see it
because it was jumping to an ‘ensure’ block, and I guess the thread would
just die. I moved the s.close into the ensure block and now it’s working
great.

In case you haven’t come across it yet:

Thread.abort_on_exception = true

will abort the whole process, instead of just killing the thread
quietly. Good for debugging…