Skip to content

Instantly share code, notes, and snippets.

@Fluxx
Created August 23, 2011 16:02
Show Gist options
  • Save Fluxx/1165618 to your computer and use it in GitHub Desktop.
Save Fluxx/1165618 to your computer and use it in GitHub Desktop.
require "rubygems"
require "eventmachine"
module DumbHttpClient
def post_init
puts "* Sending..."
puts
send_data "GET / HTTP/1.1\r\nHost: _\r\n\r\n"
puts "GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n"
@data = ""
@parsed = false
end
def receive_data data
puts "* Received..."
puts
@data << data
puts data
if !@parsed and @data =~ /[\n][\r]*[\n]/m
puts
puts "* Now we'll terminate the loop, which will also close the connection"
EventMachine::stop_event_loop
end
end
def unbind
puts "* A connection has terminated"
end
end
EventMachine::run {
EventMachine::bind_connect '192.168.42.164', 9100, "www.google.com", 80, DumbHttpClient
}
puts "* The event loop has ended"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment