User Tools

Site Tools


eventmachine

Basic usage of the Event Machine for TCP servers

require 'eventmachine'

module MyServer
  def post_init
  end
  
  def receive_data(data)
    # For long-running operations, run in a separate thread
    #EM.defer do
    #  EM.next_tick {}
    #end
    
    # To end the connection
    #close_connection_after_writing()
  end
  
  def unbind
  end
end

EM.run do
  EM.start_server hostname, port, MyServer
end
eventmachine.txt · Last modified: by reddy

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki