class method
OpenSSL::SSL::SSLSocket.open
(untyped remote_host, untyped remote_port, ?untyped local_host, ?untyped local_port, ?context: untyped) -> untyped
open(remote_host, remote_port, local_host=nil, local_port=nil, context: nil)
ext/openssl/lib/openssl/ssl.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/ext/openssl/lib/openssl/ssl.rb, line 465
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
Creates a new instance of SSLSocket. _remote_host_ and _remote_port_ are used to open TCPSocket. If _local_host_ and _local_port_ 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
Example
sock = OpenSSL::SSL::SSLSocket.open('localhost', 443) sock.connect # Initiates a connection to localhost:443
with SSLContext:
Example
ctx = OpenSSL::SSL::SSLContext.new sock = OpenSSL::SSL::SSLSocket.open('localhost', 443, context: ctx) sock.connect # Initiates a connection to localhost:443 with SSLContext