0
使用eventmachine宝石我试图在本地主机上发送和接收数据。以下是我的客户端和服务器文件的代码。EventMachine未在本地主机上接收TCP数据
server.rb
class BCCServer < EM::Connection
attr_accessor :server_socket
def post_init
puts "BCC Server"
end
def recieve_data(data)
puts "Received data: #{data}"
send_data "You sent: #{data}"
end
end
EM.run do
EM.start_server("0.0.0.0", 3000, BCCServer)
end
client.rb
class DCClient < EventMachine::Connection
def post_init
puts "Sending "
send_data "send data"
close_connection_after_writing
end
def receive_data(data)
puts "Received #{data.length} bytes"
end
def unbind
puts 'Connection Lost !'
end
end
EventMachine.run do
EventMachine::connect("127.0.0.1", 3000, DCClient)
end
我在单独的控制台执行服务器和客户端的文件。以下是客户端
客户端输出
Sending
Connection Lost !
服务器输出
BCC Server
............>>>10
的输出在服务器上的文件我已经打印接收到的数据,但它的表现” ...... ........ >>> 10" 。我在哪里做错了?
感谢
是,它在服务器上的文件错字。谢谢 – Arif