I am new to ruby and follow the book "Ruby Programming Language", I am trying to learn some Socket in ruby, and the following is my simple server / client:
require 'socket'
server= UDPSocket.new
server.bind('localhost', 3000)
loop do
data,address=server.recvfrom(1024)
server.send(data.reverse,0,address[3],address[1]) My problem
require 'socket'
ds = UDPSocket.new
while line=gets
ds.send(line.chomp, 0,'localhost', 3000)
response,address = ds.recvfrom(1024)
puts response
end
Pay attention to the line
server.send(data.reverse,0,address[3],address[1])
If I comment on this line, it seems that the server will hold on and will no longer respond to the client.
I wonder why?
Does this mean that UDPSocket must execute some kind of response to the client to continue?
source
share