From: Joe Van Dyk Date: 2005-07-01T06:14:31+09:00 Subject: Re: stupid TCP On 6/30/05, Joe Van Dyk wrote: > On 6/30/05, Joe Van Dyk wrote: > > require 'socket' > > > > tcp_server = TCPServer.new 'localhost', 4321 > > > > puts "connecting..." > > tcp_client = TCPSocket.new 'localhost', 4321 > > tcp_client.write "Hello World" > > puts "finshed writing" > > > > session = tcp_server.accept > > puts "we recieved: <#{session.gets}>" > > > > > > > > Why doesn't that work? > > Or, a threaded version: > > require 'socket' > > t = Thread.new do > tcp_server = TCPServer.new 'localhost', 4321 > while (session = tcp_server.accept) > puts "we recieved: <#{session.gets}>" > end > end > > tcp_client = TCPSocket.new 'localhost', 4321 > tcp_client.write "Hello World" > > t.join > > Still doesn't work though. :( What am I missing? Aha. I'm guessing it has something to do with not sending the data immediately. If I do tcp_client.close Then the data gets sent. But I don't want to close the socket. And I'm not seeing anything (yet) that would let me immediately send (I tried IO#flush) the data over the socket.