ruby - EventMachine not receiving TCP data on localhost -


using eventmachine gem trying send , receive data on localhost. following code of client , server files.

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   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   eventmachine::connect("127.0.0.1", 3000, dcclient) end 

i executed both server , client files in separate console. following output of client

client output

sending  connection lost ! 

server output

bcc server ............>>>10 

in server file have printed data received showing "............>>>10". doing mistake?

thanks

if @ em::connection implementation

https://github.com/eventmachine/eventmachine/blob/master/lib/em/connection.rb

def receive_data data   puts "............>>>#{data.length}" end 

method receive_data returns experiencing. means original method gets called , not yours. means 1 thing. have typo in method tried override :)

in bccserver have

recieve_data(data) 

instead of

receive_data(data) 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -