Created
October 5, 2011 19:56
-
-
Save mostlyobvious/1265506 to your computer and use it in GitHub Desktop.
This file contains 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
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 |
This file contains 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
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