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.
···
On 6/30/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
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.
From what I've seen the problem is on the reading end, not the writing
end. Try just doing
puts "we recieved: <#{session.read(5)}>"
instead of using gets. You will see "Hello", even without using a newline
(or calling puts), or closing the client socket.
In my experience most TCP problems I've had have been on the reading side.
On 6/30/05, Ryan Leavengood <mrcode@netrox.net> wrote:
Joe Van Dyk said:
> 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.
From what I've seen the problem is on the reading end, not the writing
end. Try just doing
Joe,
Just another thing to note: in TCP, the TCP stack is free to send the
data on the wire whenever it wants to. You can't force it, although
in most TCP stack implementations, a flush() is persuasive enough.
If you want a more guaranteed way of putting data on the wire whenever
you want it, you'd have to use other protocols, like UDP.