Hi All
My Server code is
$stderr.sync = $stdout.sync = true
require ‘rubygems’
require ‘eventmachine’
module EchoServer
def receive_data data
puts “Server received: #{data}”
send_data “>>>you sent: #{data}”
puts “Server sent: >>>you sent: #{data}”
(puts “CLOSING”; send_data “quit”; close_connection(true);
EM.stop) if data =~ /quit/i
end
end
EM::run{
EM::start_server “127.0.0.1”, 8100, EchoServer
}
Client code is
$stderr.sync = $stdout.sync = true
require ‘rubygems’
require ‘eventmachine’
class EchoClient < EM::Connection
def receive_data data
puts data
puts “Client Received: #{data}”
(puts “CLOSING”; close_connection(false); EM.stop) if data =~
/quit/i
end
end
cnt=0
EM::run {
emc = EM::connect “127.0.0.1”, 8100, EchoClient
EM.add_periodic_timer(5) do
cnt +=1;
if cnt < 3
emc.send_data “Message: #{cnt}”
else
emc.send_data “quit”
end
end
}
End client code
Server Output is
C:\sandbox\ruby_files>ruby serv2.rb
Server received: Message: 1
Server sent: >>>you sent: Message: 1
Server received: Message: 2
Server sent: >>>you sent: Message: 2
Server received: quit
Server sent: >>>you sent: quit
CLOSING
Client Output is
C:\sandbox\ruby_files>ruby clnt2.rb
you sent: Message: 1
Client Received: >>>you sent: Message: 1you sent: Message: 2
Client Received: >>>you sent: Message: 2
problem is server shuts down before sending the message.Any Help ?
Thanks
Bala