Skip to content

Instantly share code, notes, and snippets.

@pochi
Created May 6, 2012 16:58
Show Gist options
  • Save pochi/2623275 to your computer and use it in GitHub Desktop.
Save pochi/2623275 to your computer and use it in GitHub Desktop.
require "eventmachine"
require "net/http"
clients = 100
HOST = "localhost"
PORT = 4567
class Client < EM::Connection
attr_accessor :client_id
def initialize(args)
super
@client_id = args[:client_id].to_s
end
def post_init
Net::HTTP.start(HOST, PORT) do |http|
http.get("/login.json?id=#{client_id}")
end
EM.add_periodic_timer(1) do
Net::HTTP.start("localhost", 4567) do |http|
http.get("/update.json?id=#{client_id}")
end
end
end
end
EM.run do
clients.times do |i|
EM::connect(HOST, PORT, Client, :client_id => i)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment