SSLSocket
classin packageklyn.net.ssl
public class SSLSocket implements AutoClosable:
SSLSocket
All Implemented Interfaces: AutoClosable
Blocking TLS client socket inspired by Java's `SSLSocket`. The current API is text-oriented for now. It is suitable for protocols such as HTTP, SMTP, IMAP or custom line-based TLS protocols.
import klyn.net.ssl

socket = SSLSocket("example.com", 443)
print(socket.protocol)
print(socket.cipherSuite)
socket.close()
Fields
Modifier and Type Member Description
public SSLSocket(socket
SSLSocket(socket as Socket,
Wraps an already-connected TCP socket into TLS.
public static fromSocket(socket
fromSocket(socket as Socket,
Stable alias of `upgrade(.
public static upgrade(socket
upgrade(socket as Socket,
Upgrades an already-connected TCP socket to TLS.
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.
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.
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 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 logical line.
public receive
receive(maxBytes as Int = 4096) as String throws SSLException:
Receives up to `maxBytes` bytes interpreted as text.
public receiveBytes
receiveBytes(maxBytes as Int = 4096) as Byte[] throws SSLException:
Receives raw bytes from the peer.
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 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.
Methods inherited from AutoClosable: close