Skip to content

Instantly share code, notes, and snippets.

@mostlyobvious
Created October 5, 2011 19:56
Show Gist options
  • Save mostlyobvious/1265506 to your computer and use it in GitHub Desktop.
Save mostlyobvious/1265506 to your computer and use it in GitHub Desktop.
require 'bundler/setup'
require 'eventmachine'
module Handler
include EM::Deferrable
def connection_completed
start_tls(verify_peer: false)
end
def ssl_handshake_completed
succeed
end
end
EM.epoll
EM.run do
EM::Iterator.new(1..(ARGV.first.to_i || 999), 5).each do |n, iter|
EM.connect('127.0.0.1', 1234, Handler) do |c|
c.callback do
c.send_data("ping")
EM.add_timer(0.05) { iter.next }
end
end
end
end
require 'bundler/setup'
require 'eventmachine'
module Handler
def receive_data(data)
EM.add_timer(10) { close_connection } if data == "ping"
end
def post_init
start_tls(private_key_file: 'test.key', cert_chain_file: 'test.crt', verify_peer: false)
end
def unbind
puts "closing #{object_id}"
end
end
puts Process.pid
EM.epoll
EM.run { EM.start_server('127.0.0.1', 1234, Handler) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment