From: Eleanor McHugh Date: 2009-03-16T20:44:48+09:00 Subject: Re: Socket hangs when I read after writing! On 16 Mar 2009, at 09:32, Just Another Victim of the Ambient Morality wrote: > Okay, I can shed some more light on this problem. > If the service I'm connecting to is the first one to send data > and my > program reads that data like so: > > > sock = TCPSocket.new('host.com', 12345) > > line = sock.readline > puts line > > > ....even if the service sends several lines, sock.readline won't > return > until the connection is closed. This sounds like it may be a bug > specific > to the Win32 implementation of Ruby 1.8 but that's just a guess. > Does anyone know what's going on here? I'll see if I can find time to look at this properly later, however looking at this snippet I have to ask if readline is what you really want to be doing: i.e. is the server sending messages which are terminated with a newline? Because if not sock.readline will just sit there buffering input from the server until the socket is closed. BTW, if you follow the link in my .sig file you'll find several presentations with lots of Ruby socket code in them which might help with your experiments. None of them have been tested on Windows so YMMV but they should be good for general inspiration. Ellie Eleanor McHugh Games With Brains http://slides.games-with-brains.net ---- raise ArgumentError unless @reality.responds_to? :reason