Method: OpenSSL::SSL::SSLSocket.open
- Defined in:
- lib/openssl/ssl.rb
.open(remote_host, remote_port, local_host = nil, local_port = nil, context: nil) ⇒ Object
call-seq:
open(remote_host, remote_port, local_host=nil, local_port=nil, context: nil)
Creates a new instance of SSLSocket. remotehost_ and remoteport_ are used to open TCPSocket. If localhost_ and localport_ are specified, then those parameters are used on the local end to establish the connection. If context is provided, the SSL Sockets initial params will be taken from the context.
Examples
sock = OpenSSL::SSL::SSLSocket.open('localhost', 443)
sock.connect # Initiates a connection to localhost:443
with SSLContext:
ctx = OpenSSL::SSL::SSLContext.new
sock = OpenSSL::SSL::SSLSocket.open('localhost', 443, context: ctx)
sock.connect # Initiates a connection to localhost:443 with SSLContext
470 471 472 473 474 475 476 477 |
# File 'lib/openssl/ssl.rb', line 470 def open(remote_host, remote_port, local_host=nil, local_port=nil, context: nil) sock = ::TCPSocket.open(remote_host, remote_port, local_host, local_port) if context.nil? return OpenSSL::SSL::SSLSocket.new(sock) else return OpenSSL::SSL::SSLSocket.new(sock, context) end end |