os
sleep
fun sleep(ms: double) > void
Sleep for the given amount of ms
time
fun time() > double
Returns: epoch time in ms
env
fun env(key: str) > str?
Returns environment variable under key
key: environment variable name
tmpDir
fun tmpDir() > str
Returns: path to system temp directory
tmpFilename
fun tmpFilename(prefix: str?) > str
prefix: prefix to the temp file name Returns: a temporary file name in system tmp dir
exit
fun exit(exitCode: int) > void
Exit program with exitCode
exitCode: exit code
execute
fun execute(command: [str]) > int !> FileSystemError, ExecError, UnexpectedError
Execute command and return its exit code
command: command to execute Returns: exit code of the command
SocketProtocol
enum SocketProtocol {
tcp,
udp,
ipc,
}
Protocols supported over a socket
Socket
object Socket
A socket
connect
static fun connect(address: str, port: int = 0, netProtocol: SocketProtocol) > Socket !> InvalidArgumentError, SocketError, FileSystemError, NotYetImplementedError, UnexpectedError
Opens a socket
address: A string containing either a IPv4, IPv6 or path to a socket file (IPC)port: Port to which to connectprotocol: Protocol to use Returns: A newSocketopened and ready to use
close
fun close() > void
Close the socket
receive
fun receive(n: int) > str? !> InvalidArgumentError, ReadWriteError
Receive at most n bytes from the socket
n: How many bytes we're prepare to receive Returns: The bytes received or null if nothing to read
receiveLine
fun receiveLine(maxSize: int?) > str? !> ReadWriteError
Receive from socket until it's closed or a linefeed is received Returns: The bytes received or null if nothing to read
receiveAll
fun receiveAll(maxSize: int?) > str? !> ReadWriteError
Receive from socket until it's closed Returns: The bytes received or null if nothing to read
send
fun send(bytes: str) > void !> ReadWriteError
Send bytes on the socket
bytes: Bytes to send
TcpServer
object TcpServer
A TCP Server
init
static fun init(address: str, port: int, reuseAddr: bool) > TcpServer !> SocketError, UnexpectedError, InvalidArgumentError
Starts a TCP server
address: Address to listen onport: Port to listen onreuseAddr: Wether we want to accept multiple connections Returns: NewTcpServerbound to<address>:<port>
accept
fun accept() > Socket !> SocketError, UnexpectedError
Accept a new connection Returns: Socket opened with the client
close
fun close() > void
Close server
