public
Description: Wrapper around Ruby's standard HTTP libraries to make them evented (if EventMachine is running)
Homepage: http://github.com/arunthampi/evented_net
Clone URL: git://github.com/arunthampi/evented_net.git
arunthampi (author)
Wed Aug 20 17:20:44 -0700 2008
commit  60900d8ba0412258e1064b0263deab17bd90c8b2
tree    7656098c91c95dc7327f1259ffdf07e9d8b166a1
parent  9232ecc3c32e8aeec052557061c889290350fcd4
evented_net / examples / evented_get.rb
100644 24 lines (19 sloc) 0.695 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Most of this code is stolen from Igvita's excellent blog post on EventMachine:
# http://www.igvita.com/2008/05/27/ruby-eventmachine-the-speed-demon/
 
require File.dirname(__FILE__) + "/../lib/evented_net"
require 'evma_httpserver'
 
class Handler < EventMachine::Connection
  include EventMachine::HttpServer
 
  def process_evented_http_req(code, body)
    puts "Code: #{code} Body: #{body}"
  end
 
  def process_http_request
    uri = URI.parse('http://www.maxmind.com/app/locate_ip')
    EventedNet::HTTP.get(uri, :callback => method(:process_evented_http_req))
  end
end
 
EventMachine::run {
  EventMachine.kqueue
  EventMachine::start_server("0.0.0.0", 8082, Handler)
  puts "Listening"
}