← index

TlsSocket

inherits Object

A TLS-encrypted TCP connection, with the same read/write surface as TcpSocket.

connect: speaks TLS from the first byte (certificate checked against the host name); wrap:host: upgrades an existing plaintext TcpSocket in place — the STARTTLS pattern — consuming it. The insecure: variants take a Boolean that, when true, skips certificate validation: local debugging only, the word at the call site is the warning. The do: forms scope the socket to a block, closing it on every exit path.

TlsSocket.connect:'example.com:443' do:{ |sock|
sock.writeAll:'GET / HTTP/1.0\r\nHost: example.com\r\n\r\n'.asBytes
sock.readAll
}

Class methods

connect:

Connect to 'host:port' speaking TLS from the first byte; the host part is also the certificate / SNI name. A failed handshake (or a certificate that doesn't validate) throws a catchable IoError.

native

connect: do:

Connect with TLS, run the block with the socket, and close it on every exit path (normal, throw, or cancel); answers the block's value.

native

connect: insecure:

connect:, with certificate validation skipped when the Boolean is true — for local debugging against self-signed certificates, never production.

native

connect: insecure: do:

The scoped (do:) form of connect:insecure:.

native

wrap: host:

Upgrade an already-connected TcpSocket to TLS in place (the STARTTLS pattern). host: names the certificate / SNI identity — supplied explicitly because the connection may have been made by IP or via a proxy. The TcpSocket is *consumed*: it is left closed whether the handshake succeeds or not.

native

wrap: host: do:

Upgrade a TcpSocket to TLS, run the block with the TlsSocket, and close it on every exit path; answers the block's value.

native

wrap: host: insecure:

wrap:host:, with certificate validation skipped when the Boolean is true (local debugging only).

native

wrap: host: insecure: do:

The scoped (do:) form of wrap:host:insecure:.

native

Instance methods

byteStream

A buffered ByteStream that *consumes* this socket: the connection transfers to the stream and the socket is left closed (further ops on it throw). Adds read-ahead, peek:, and delimiter framing (readUntil:) over the raw socket.

native

close

Close the socket (idempotent — a second close is a no-op). Further operations throw. Returns nil.

native

closed?

Whether the socket has been closed — including by being consumed into a stream or a TLS upgrade.

native

read:Integer

Up to n bytes as Bytes — one read, so possibly fewer than asked; empty Bytes means the peer closed (EOF). Parks the task until data arrives. Throws on a closed socket or an I/O error. For buffered or delimiter-framed reading, wrap the socket in byteStream.

native

readAll

Read until the peer closes, answering everything as one Bytes. Only returns once the other side signals EOF — for request/response protocols where the peer keeps the connection open, frame reads with read: or a byteStream instead.

native

stringStream

A text StringStream that *consumes* this socket (a byteStream immediately wrapped): readLine / eachLine: / writeln: over the connection, decoding UTF-8.

native

writeAll:Bytes

Write all of the Bytes to the socket — complete or throw, no short writes. Returns nil.

native