Skip to content

Network

The @std/net standard library contains packages for network and device communication.

PackageDescription
@std/net/telnetConnect to a Telnet server, write data, read lines with a timeout, and close the connection.
@std/net/sshConnect to an SSH server using password or key authentication, write/read shell data, run commands, check state, and close the connection.
@std/net/serialOpen a serial port, write data, read data with a timeout, and close the port.
import telnet from "@std/net/telnet"
import ssh from "@std/net/ssh"
import serial from "@std/net/serial"

All three packages create a connection-like object, then expose methods for reading, writing, and closing.

const conn = telnet.Telnet("127.0.0.1", 2323)
defer conn.close()
conn.write("ping\n")
const out = conn.read(2000)
println(out)

Use -> only when describing a function value type.

let reader: fn(int) -> string

When writing a function implementation, put the return type after the parameter list.

fn readOnce(timeoutMs: int) string {
return conn.read(timeoutMs)
}

For a function that returns nothing, use void.

fn closeConn() void {
conn.close()
}