Created
April 10, 2011 14:36
-
-
Save shelling/912388 to your computer and use it in GitHub Desktop.
hello EventMachine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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