Skip to content

Instantly share code, notes, and snippets.

@richardc
Last active August 29, 2015 14:09
Show Gist options
  • Save richardc/b5a1d4d28c8bbae24cd5 to your computer and use it in GitHub Desktop.
Save richardc/b5a1d4d28c8bbae24cd5 to your computer and use it in GitHub Desktop.
#!/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