Hi,
I use the code below to create a TCP/IP server and then the client code to call it but for some reason the server doesn't receive the message sent by the client. Please advise. Thanks
Server:
class MyServer < GServer def initialize(port=20607, host=GServer::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
Client:
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."