From: Robert Klemme Date: 2009-03-16T21:15:06+09:00 Subject: Re: Socket hangs when I read after writing! 2009/3/16 Just Another Victim of the Ambient Morality : > > "Just Another Victim of the Ambient Morality" wrote > in message news:%Qkvl.43684$Yx2.7782@en-nntp-06.dc1.easynews.com... >>    I have the following Ruby program: >> >> >> sock = TCPSocket.new('host.com', 12345) >> >> sock.write('This is a test') >> >> data = sock.read(1024) >> puts data >> >> >>    ...The service this connection connects to just reads the string and >> write a response which this program then tries to read.  I expected it to >> just work but instead it just hangs.  The weird part is that it hangs >> before the data is actually written out through the socket.  The service >> on the other end doesn't get any data.  If I remove the end part of the >> program that attempts to read the response, the data makes it through and >> is read correctly by the service. >>    What is wrong with my program?  Why is it hanging? >>    Thank you... > >    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? >    Thank you... Can you post the code of the other side? Maybe the other side does not flush the output because you do not close the write channel and the other side still expects more input. There are plenty of other things that could go wrong but seeing only this bit of code it is difficult to come up with more helpful replies. Cheers robert -- remember.guy do |as, often| as.you_can - without end