Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Monitoring Socket Disconnect during gets or readline

Thread Tools

Monitoring Socket Disconnect during gets or readline

Jon Fi
Posts: n/a
Hello... I am writing a simple chat program, but i have encountered a
problem. I ask for a client to provide a handle, but it he disconnects
during a gets call, it does weird things.

def get_handle(session)
for attempt in (0..2)
session.print "Please Login\n"

response=session.gets.strip  # The problem

if(!@socketHash.has_value?(response))  # This just checks to make
sure the handle isn't in use.
return response
session.print "Handle alerady in use... "
If the client disconnects at this point, ruby seems to be still waiting
for a response. Also, sometimes it sends ruby's processor usage to 100%.

Is there a better way to do this? Or is there a way to give gets a
timeout? Thanks!

Posted via

Reply With Quote
Posts: n/a
On 10/3/06, Paul Lutus <(E-Mail Removed)> wrote:
> IO#gets blocks forever if the input goes away, while IO#readline throws an
> exception on EOF. I think your situation qualifies as an EOF. Why not try
> it?

Use Eventmachine (

The need for painless network programming in ruby.

There was only one Road; that it was like a great river: its springs
were at every doorstep, and every path was its tributary.

Reply With Quote

Thread Tools

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
compiling python 3.1.2 with local readline fails to get readline - help! gavino Python 4 09-20-2010 05:17 AM
Getting application ReadLine and Perl debugger ReadLine to cooperate Andrew DeFaria Perl Misc 1 01-30-2008 11:46 PM
Readline::readline() blocking all other threads Jean-Michel Ruby 0 12-22-2007 01:00 AM
Why OE6 disconnect Bell Dial-Up during receiving mails Computer Support 2 04-24-2006 12:40 PM
Socket#gets and Socket#puts James Edward Gray II Ruby 1 11-25-2004 03:00 AM