1
接收數據有代碼,客戶端:TCP客戶機不能從EventMachine的
require 'rubygems'
require 'benchmark'
require 'socket'
i=0
TCPSocket.open "127.0.0.1", 8080 do |s|
s.send "#{i}th sending", 0
if line = s.gets
puts line
end
end
服務器:
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..."
}
客戶端不能打印任何東西