How do you break out of a server.accept loop?

R

Ralph Smith

This works, but I don't know how to get out of the loop. I'm running this on windows xp.
I tried control-c, but it doesn't work. How can I get out of a loop like this?



require 'socket'

server = TCPServer.new('127.0.0.1', 8080)

while (session = server.accept)
session.puts session.gets
session.close
end


thanks,
Ralph
 
D

Daniel Berger

Ralph said:
This works, but I don't know how to get out of the loop. I'm running this on windows xp.
I tried control-c, but it doesn't work. How can I get out of a loop like this?



require 'socket'

server = TCPServer.new('127.0.0.1', 8080)

while (session = server.accept)
session.puts session.gets
session.close
end


thanks,
Ralph

Put "Thread.new { loop { sleep 0.01 } }" somewhere near the top of your program.

Regards,

Dan
 
R

Robert Klemme

Ralph said:
This works, but I don't know how to get out of the loop. I'm running
this on windows xp. I tried control-c, but it doesn't work. How can I
get out of a loop like this?

You can for example write an event handler that throws an exception in the
accepting thread.
require 'socket'

server = TCPServer.new('127.0.0.1', 8080)

while (session = server.accept)
session.puts session.gets
session.close
end

Kind regards

robert
 
P

Pit Capitain

Ralph said:
This works, but I don't know how to get out of the loop. I'm running this on windows xp.
I tried control-c, but it doesn't work. How can I get out of a loop like this?

require 'socket'

server = TCPServer.new('127.0.0.1', 8080)

while (session = server.accept)
session.puts session.gets
session.close
end

Try CTRL-BREAK.

Regards,
Pit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top