SSLSocket
classin packageklyn.net.ssl
public class SSLSocket implements AutoClosable
SSLSocket
All Implemented Interfaces: AutoClosable

Blocking TLS client socket.

Supports text protocols and binary transfers into reusable buffers. Peer certificates are verified by the default client context. Unix uses the system OpenSSL provider and its default trust paths. Windows uses native Schannel and the system certificate stores, without OpenSSL DLLs. An explicit SSLContext CA file/path overrides the default trust roots. Certificate-chain and server-name validation remain enabled by default.

import klyn.net.ssl

socket = SSLSocket("example.com", 443)
print(socket.protocol)
print(socket.cipherSuite)
socket.close()
Properties
Modifier and Type Member Description
public readonly property cipherSuite
cipherSuite as String
Negotiated cipher suite.
public readonly property context
context as SSLContext
TLS context applied to this socket.
public readonly property host
host as String
Remote host name.
public readonly property isConnected
isConnected as Boolean
True when the socket is connected.
public readonly property port
port as Int
Remote port number.
public readonly property protocol
protocol as String
Negotiated TLS protocol, for example TLSv1.3.
public readonly property reader
reader as SSLSocketReader
Read-only alias for getReader().
public readonly property writer
writer as SSLSocketWriter
Read-only alias for getWriter().
Constructors
Modifier and Type Member Description
public SSLSocket
SSLSocket(context as SSLContext = null)
Creates an unconnected TLS socket.
public SSLSocket
SSLSocket(host as String, port as Int, context as SSLContext = null) throws SSLException
Creates and connects a TLS socket.
public SSLSocket
SSLSocket(socket as Socket, host as String, port as Int, context as SSLContext = null) throws SSLException
Wraps an already-connected TCP socket into TLS.
Methods
Modifier and Type Member Description
public attachToSocket
attachToSocket(socket as Socket, host as String, port as Int) as Void throws SSLException
Upgrades an already-connected TCP socket using this TLS context.
public override close
close() as Void
Closes the TLS socket.
public connect
connect(host as String, port as Int) as Void throws SSLException
Connects this TLS socket.
public static fromSocket
fromSocket(socket as Socket, host as String, port as Int, context as SSLContext = null) as SSLSocket throws SSLException
Stable alias of upgrade(...) for wrapping an existing TCP socket in TLS.
public getInputStream
getInputStream() as SSLSocketInputStream
Returns the input stream facade.
public getOutputStream
getOutputStream() as SSLSocketOutputStream
Returns the output stream facade.
public getReader
getReader() as SSLSocketReader
Returns the text reader facade.
public getWriter
getWriter() as SSLSocketWriter
Returns the text writer facade.
public readAllText
readAllText() as String throws SSLException
Reads until the peer closes the TLS stream.
public readLine
readLine() as String throws SSLException
Reads one line from the TLS stream.
public receive
receive(maxBytes as Long = 4096) as String throws SSLException
Receives up to maxBytes bytes interpreted as text.
public receiveBytes
receiveBytes(maxBytes as Long = 4096) as Byte[] throws SSLException
Receives raw bytes from the peer.
public receiveInto
receiveInto(notnull buffer as Byte[], offset as Long = 0l, length as Long = -1l) as Long
Receives bytes directly into a reusable buffer without changing its size.
public send
send(value as String) as Boolean throws SSLException
Sends text to the peer.
public sendBytes
sendBytes(value as Byte[]) as Int throws SSLException
Sends raw bytes to the peer.
public override toString
toString() as String
No summary.
public static upgrade
upgrade(socket as Socket, host as String, port as Int, context as SSLContext = null) as SSLSocket throws SSLException
Upgrades an already-connected TCP socket to TLS.
public write
write(value as String) as Void throws SSLException
Writes text to the peer.
public writeBytes
writeBytes(value as Byte[]) as Void throws SSLException
Writes raw bytes to the peer.
public writeLine
writeLine(value as String) as Void throws SSLException
Writes one line to the peer.
Inherited Methods
methodInherited Methods from AutoClosable: close