public class SSLSocket implements 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()| Modifier and Type | Member | Description |
|---|---|---|
| public readonly property | cipherSuitecipherSuite as String |
Negotiated cipher suite. |
| public readonly property | contextcontext as SSLContext |
TLS context applied to this socket. |
| public readonly property | hosthost as String |
Remote host name. |
| public readonly property | isConnectedisConnected as Boolean |
True when the socket is connected. |
| public readonly property | portport as Int |
Remote port number. |
| public readonly property | protocolprotocol as String |
Negotiated TLS protocol, for example TLSv1.3. |
| public readonly property | readerreader as SSLSocketReader |
Read-only alias for getReader(). |
| public readonly property | writerwriter as SSLSocketWriter |
Read-only alias for getWriter(). |
| Modifier and Type | Member | Description |
|---|---|---|
| public | SSLSocketSSLSocket(context as SSLContext = null) |
Creates an unconnected TLS socket. |
| public | SSLSocketSSLSocket(host as String, port as Int, context as SSLContext = null) throws SSLException |
Creates and connects a TLS socket. |
| public | SSLSocketSSLSocket(socket as Socket,
host as String,
port as Int,
context as SSLContext = null) throws SSLException |
Wraps an already-connected TCP socket into TLS. |
| Modifier and Type | Member | Description |
|---|---|---|
| public | attachToSocketattachToSocket(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 | closeclose() as Void |
Closes the TLS socket. |
| public | connectconnect(host as String, port as Int) as Void throws SSLException |
Connects this TLS socket. |
| public static | fromSocketfromSocket(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 | getInputStreamgetInputStream() as SSLSocketInputStream |
Returns the input stream facade. |
| public | getOutputStreamgetOutputStream() as SSLSocketOutputStream |
Returns the output stream facade. |
| public | getReadergetReader() as SSLSocketReader |
Returns the text reader facade. |
| public | getWritergetWriter() as SSLSocketWriter |
Returns the text writer facade. |
| public | readAllTextreadAllText() as String throws SSLException |
Reads until the peer closes the TLS stream. |
| public | readLinereadLine() as String throws SSLException |
Reads one line from the TLS stream. |
| public | receivereceive(maxBytes as Long = 4096) as String throws SSLException |
Receives up to maxBytes bytes interpreted as text. |
| public | receiveBytesreceiveBytes(maxBytes as Long = 4096) as Byte[] throws SSLException |
Receives raw bytes from the peer. |
| public | receiveInto | Receives bytes directly into a reusable buffer without changing its size. |
| public | sendsend(value as String) as Boolean throws SSLException |
Sends text to the peer. |
| public | sendBytessendBytes(value as Byte[]) as Int throws SSLException |
Sends raw bytes to the peer. |
| public override | toStringtoString() as String |
No summary. |
| public static | upgradeupgrade(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 | writewrite(value as String) as Void throws SSLException |
Writes text to the peer. |
| public | writeByteswriteBytes(value as Byte[]) as Void throws SSLException |
Writes raw bytes to the peer. |
| public | writeLinewriteLine(value as String) as Void throws SSLException |
Writes one line to the peer. |