ruby - The tcp client can not receive data from eventmachine -
there code, client:
require 'rubygems' require 'benchmark' require 'socket' i=0 tcpsocket.open "127.0.0.1", 8080 |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 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 interaction between s.gets in client , send_data "send_response" in server.
your small test works fine me when change:
send_data "send_response" to
send_data "send_response\n" the s.gets waiting newline remote client. none comes.
Comments
Post a Comment