Joe Van Dyk
6/30/2005 9:15:00 PM
On 6/30/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> On 6/30/05, Joe Van Dyk <joevandyk@gmail.com> 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.