From: Brian Candler Date: 2010-06-17T16:52:14+09:00 Subject: Re: Socket Problems Doug Jolley wrote: > require 'socket' Socket.do_not_reverse_lookup = true # speeds things up > socket=TCPSocket::new('ip','port') > puts("Connect:\n"+socket.read()+"\n\n") Aside: port is usually an integer not a string (unless you're giving a service name from /etc/services) But the main problem is that socket.read will block until the other end drops the connection. You probably want socket.gets instead. Other options include socket.readpartial(n) which will read *up to* n bytes, which you may have to repeat until you have the whole response; or if the protocol is length-framed, then use e.g. socket.read(4) to read the length, followed by socket.read(len). But that doesn't seem to be the case here. I don't know the semantics of fread($fp,1000) in PHP, but from your code I'd guess it doesn't actually wait until 1000 bytes are available, but just reads up to 1000 bytes. HTH, Brian. -- Posted via http://www.ruby-forum.com/.