Skip to content

Instantly share code, notes, and snippets.

@shelling
Created April 10, 2011 14:36
Show Gist options
  • Select an option

  • Save shelling/912388 to your computer and use it in GitHub Desktop.

Select an option

Save shelling/912388 to your computer and use it in GitHub Desktop.
hello EventMachine
#!/usr/bin/env ruby
#-*- mode: ruby -*-
require 'rubygems'
require "eventmachine"
require "evma_httpserver"
class EchoServer < EM::Connection
include EM::HttpServer
def post_init
super
no_environment_strings
end
def process_http_request
response = EM::DelegatedHttpResponse.new(self)
response.status = 200
response.content_type 'text/html'
response.content = "<h1>Hello</h1>"
response.send_response
end
end
EventMachine::run do
puts "start timer"
EventMachine::add_timer(1) do
puts "first"
end
EventMachine::add_timer(1.1) do
EventMachine::stop
end
end
EventMachine::run do
puts "start server"
EventMachine::start_server "localhost", 8080, EchoServer
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment