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