Last active
August 29, 2015 14:09
-
-
Save richardc/b5a1d4d28c8bbae24cd5 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
#!/usr/bin/env ruby | |
require 'socket' | |
require 'openssl' | |
def ssl_connect(host, port) | |
tcp_socket = TCPSocket.new host, port | |
puts "tcp connected" | |
ctx = OpenSSL::SSL::SSLContext.new | |
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
socket = OpenSSL::SSL::SSLSocket.new(tcp_socket, ctx) | |
socket.sync_close = true | |
socket.connect | |
puts "ssl handshake done" | |
return socket | |
end | |
i = 0 | |
loop do | |
i = i + 1 | |
socket = ssl_connect('localhost', 61614) | |
Thread.new do | |
# killer thread | |
sleep 0.2 | |
socket.close | |
end | |
puts "reading #{i}" | |
begin | |
line = socket.gets | |
rescue Errno::EBADF => e | |
puts "caught #{e}, reconnecting" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment