v2026.11.0
All Bundles
Bundle

Provides network support

TCPSecureSocket

Secure SSL TCP/IP socket

Operations

Close #

Closes the socket.

If this side has just written data and the peer has not read it yet, prefer `CloseGracefully()`. On Windows loopback, closing first can discard what was just written -- see that method and `docs/windows_loopback_sockets.md`.

method : public : Close() ~ Nil

CloseGracefully #

Closes the socket after letting the peer read what was written and hang up first.

The TLS twin of `TCPSocket->CloseGracefully()`, and exposed to the same thing: the discard happens in the transport underneath TLS, so encrypting the payload does not change the race. On Windows over loopback, a peer that writes and then immediately closes can have that data discarded -- the reader gets a reset and zero bytes rather than a short read. The remedy is to not be the side that closes first (`docs/windows_loopback_sockets.md`).

Reads and discards anything still arriving until the peer closes, then closes. Bounded on both sides so it cannot park a thread: `timeout_ms` of silence, or 16 reads of a peer that keeps sending instead of hanging up.

method : public : CloseGracefully(timeout_ms:Int) ~ Nil

Parameters

NameTypeDescription
timeout_msInthow long to wait, in milliseconds, for the peer to close

Flush #

Flushes the output buffer. This is a no-opt given this socket is not backed by an output buffer.

method : public : Flush() ~ Nil

GetAddress #

Returns the connected network address

method : public : GetAddress() ~ String

Return

TypeDescription
Stringreturn network address

GetCertFingerprint #

Returns the SHA-256 fingerprint of the peer certificate as a hex string

method : public : GetCertFingerprint() ~ String

Return

TypeDescription
String64-char hex fingerprint, or Nil if unavailable

GetIssuer #

Gets the X.509 certificate issuer name

method : public : GetIssuer() ~ String

Return

TypeDescription
Stringcertificate issuer name

GetLastError # function

Gets the calling thread's last TLS failure, from a connect, listen, accept, read or write; each of those replaces it, and one that works leaves none. A connect that failed says why the system refused it, e.g. "NET - The connection to the given server / port failed: Connection refused". A certificate that failed verification is described with each reason mbedTLS gives, e.g. "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed: The certificate is not correctly signed by the trusted CA".

function : GetLastError() ~ String

Return

TypeDescription
Stringlast error message, or Nil if there was none

GetPort #

Returns the connected network port

method : public : GetPort() ~ Int

Return

TypeDescription
Intreturn network port

GetSubject #

Gets the X.509 certificate subject name

method : public : GetSubject() ~ String

Return

TypeDescription
Stringcertificate subject name

IsOpen #

Returns rather the socket is open

method : public : IsOpen() ~ Bool

Return

TypeDescription
Booltrue if socket is open, false otherwise

New # constructor

Connects and completes a TLS handshake. The server's certificate is always verified: its chain must lead to a trusted certificate, and it must name the address connected to (a DNS name, or an IP address in an iPAddress subjectAltName). A certificate that fails is refused: IsOpen() is false and GetLastError() says why. To trust a server whose certificate no public authority signed, such as a self-signed one, pass that certificate as pem. Verification is relaxed only for the whole process, by setting OBJECK_TLS_INSECURE_SKIP_VERIFY=1 for testing, and then only an untrusted issuer is accepted.

New(address:System.String, port:Int, pem:String)

Parameters

NameTypeDescription
addressStringnetwork address
portIntnetwork port
pemStringPEM file of the certificates to trust, in place of the bundled certificate authorities (optional)

ReadBuffer #

Reads bytes into a byte buffer

method : public : ReadBuffer(offset:Int, num:Int, buffer:Byte[]) ~ Int

Parameters

NameTypeDescription
offsetIntdestination buffer offset
numIntnumber of values to read
bufferByteinput buffer

Return

TypeDescription
Intnumber of values read

ReadBuffer #

Reads bytes into a character buffer

method : public : ReadBuffer(offset:Int, num:Int, buffer:Char[]) ~ Int

Parameters

NameTypeDescription
offsetIntdestination buffer offset
numIntnumber of values to read
bufferCharinput buffer

Return

TypeDescription
Intnumber of values read

ReadByte #

Reads a byte

method : public : ReadByte() ~ Byte

Return

TypeDescription
Bytebyte read

ReadLine # native

Reads a string until a newline or character return is detected

method : public : native : ReadLine() ~ System.String

Return

TypeDescription
Stringcharacter string

Select #

Checks if read/write data is available

method : public : Select(is_write:Bool) ~ Int

Parameters

NameTypeDescription
is_writeBoolif true check for write, otherwise read

Return

TypeDescription
Int1 if ready, 0 if not ready, -1 is error

SetKeepAlive #

Sets the TCP keep-alive option

method : public : SetKeepAlive(enable:Bool) ~ Bool

Parameters

NameTypeDescription
enableBooltrue to enable, false to disable

Return

TypeDescription
Booltrue if successful

SetMinTLSVersion #

Sets minimum TLS protocol version. Call before New() to take effect. Use mbedTLS MBEDTLS_SSL_VERSION_* constants.

method : public : SetMinTLSVersion(ver:Int) ~ Bool

Parameters

NameTypeDescription
verIntTLS version constant

Return

TypeDescription
Booltrue if successful

SetNoDelay #

Disables Nagle's algorithm (TCP_NODELAY)

method : public : SetNoDelay(enable:Bool) ~ Bool

Parameters

NameTypeDescription
enableBooltrue to disable Nagle, false to re-enable

Return

TypeDescription
Booltrue if successful

SetRecvBufferSize #

Sets the receive buffer size

method : public : SetRecvBufferSize(bytes:Int) ~ Bool

Parameters

NameTypeDescription
bytesIntbuffer size in bytes

Return

TypeDescription
Booltrue if successful

SetRecvTimeout #

Sets the receive timeout

method : public : SetRecvTimeout(ms:Int) ~ Bool

Parameters

NameTypeDescription
msInttimeout in milliseconds

Return

TypeDescription
Booltrue if successful

SetSendBufferSize #

Sets the send buffer size

method : public : SetSendBufferSize(bytes:Int) ~ Bool

Parameters

NameTypeDescription
bytesIntbuffer size in bytes

Return

TypeDescription
Booltrue if successful

SetSendTimeout #

Sets the send timeout

method : public : SetSendTimeout(ms:Int) ~ Bool

Parameters

NameTypeDescription
msInttimeout in milliseconds

Return

TypeDescription
Booltrue if successful

SetVerifyPeer #

Confirms that the peer's certificate was verified. Verification is settled by the handshake in New() and cannot be turned off afterwards; false never relaxes it.

method : public : SetVerifyPeer(strict:Bool) ~ Bool

Parameters

NameTypeDescription
strictBooltrue to confirm verification is required

Return

TypeDescription
Booltrue if strict is true and the certificate was verified as required; false if strict is false (nothing changes) or the process is in insecure test mode (OBJECK_TLS_INSECURE_SKIP_VERIFY)

WriteBuffer #

Writes bytes from a byte buffer

method : public : WriteBuffer(buffer:Byte[]) ~ Int

Parameters

NameTypeDescription
bufferByteinput buffer

Return

TypeDescription
Intnumber of values written

WriteBuffer #

Writes bytes from a byte buffer

method : public : WriteBuffer(offset:Int, num:Int, buffer:Byte[]) ~ Int

Parameters

NameTypeDescription
offsetIntdestination buffer offset
numIntnumber of values to write
bufferByteinput buffer

Return

TypeDescription
Intnumber of values written

WriteBuffer #

Writes characters from a byte buffer

method : public : WriteBuffer(buffer:Char[]) ~ Int

Parameters

NameTypeDescription
bufferCharinput buffer

Return

TypeDescription
Intnumber of values written

WriteBuffer #

Writes characters from a character buffer

method : public : WriteBuffer(offset:Int, num:Int, buffer:Char[]) ~ Int

Parameters

NameTypeDescription
offsetIntdestination buffer offset
numIntnumber of values to write
bufferCharinput buffer

Return

TypeDescription
Intnumber of values written

WriteByte #

Writes a byte

method : public : WriteByte(b:Int) ~ Bool

Parameters

NameTypeDescription
bIntbyte to write

Return

TypeDescription
Booltrue if byte was written, false otherwise

WriteString #

Writes a character string

method : public : WriteString(str:System.String) ~ Nil

Parameters

NameTypeDescription
strStringstring to be written