Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Monitoring Socket Disconnect during gets or readline
Jon Fi
10/2/2006 2:47:00 PM
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.
[code]
def get_handle(session)
for attempt in (0..2)
session.print "Please Login\n"
response=session.gets.strip # The problem
re=/(Login)\s(.+)/
md=re.match(response)
response=md[2]
if(!@socketHash.has_value?(response)) # This just checks to make
sure the handle isn't in use.
return response
else
session.print "Handle alerady in use... "
end
end
end
[/code]
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!
-Jon
--
Posted via
http://www.ruby-...
.
2 Answers
Paul Lutus
10/3/2006 12:48:00 AM
0
Jon Fi wrote:
> 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.
/...
> 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!
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?
--
Paul Lutus
http://www.ara...
hemant
10/3/2006 12:45:00 PM
0
On 10/3/06, Paul Lutus <nospam@nosite.zzz> 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 (
http://rubyforge.org/projects/ev...
).
The thing...you 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.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Monitoring Socket Disconnect during gets or readline
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password