我使用下面的代码创建一个TCP/IP服务器,然后使用客户端代码调用它,但由于某些原因,服务器没有接收到客户端发送的消息。请指导。谢谢。
服务器
class MyServer < GServer
def initialize(port=20607, host=G服务器:DEFAULT_HOST)
super(port, host, Float::MAX, $stderr, true)
end
def serve(sock)
begin
@clients << sock
stock.accept
message = sock.gets.chomp
puts "message: " << message
this.stop if message == "#quitserver"
# TODO: code that process commmands comes here
rescue
ensure
@clients.delete(sock)
end
end
end
客户:
require socket
streamSock = TCPSocket.new( "127.0.0.1", 20607 )
puts "Socket created..." unless streamSock.nil?
sleep 5
streamSock.puts "hello world"
sleep 5
streamSock.close
puts "Socket closed."