The tcp client can not receive data from eventmachine
there is the code, the client:
require 'rubygems'
require 'benchmark'
require 'socket'
i=0
T开发者_运维问答CPSocket.open "127.0.0.1", 8080 do |s|
s.send "#{i}th sending", 0
if line = s.gets
puts line
end
end
the server:
require 'rubygems'
require 'benchmark'
require 'eventmachine'
class Handler < EventMachine::Connection
def receive_data(data)
sleep 2 # simulate a long running request
send_data "send_response"
puts data
end
end
EventMachine::run {
EventMachine::start_server("0.0.0.0", 8080, Handler)
puts "Listening..."
}
The client can not print anything
It's an interaction between s.gets
in the client and send_data "send_response"
in the server.
Your small test works fine for me when I change:
send_data "send_response"
to
send_data "send_response\n"
The s.gets
is waiting for a newline from the remote client. None comes.
精彩评论