std::netTCP networking.
Create TCP servers and clients for bidirectional byte-stream
communication. Handle types (Listener, Connection) provide
type-safe wrappers over raw file descriptors.
import std::net;
fn main() {
let listener = net.listen(":9000");
let conn = listener.accept();
let data = conn.read();
conn.write(data);
conn.close();
}
listenCreate a TCP listener bound to the given address.
The address format is "host:port" or ":port".
let listener = net.listen(":9000");
connectConnect to a TCP server at the given address.
Blocks until the connection is established.
let conn = net.connect("localhost:9000");
connect_timeoutConnect to a TCP server with a timeout.
timeout_sec and timeout_usec specify the deadline.
broadcast_exceptBroadcast a message to all connections except the sender.
Used in chat-server patterns to fan out messages.
ListenerA TCP listener bound to an address, waiting for connections.
Created by net.listen(addr). Returns a negative value (as i32)
on failure when cast; use comparison to check success.
ConnectionAn established TCP connection for reading and writing.
Obtained from listener.accept() or net.connect(addr).
ListenerMethodsMethods available on a TCP Listener.
ConnectionMethodsMethods available on a TCP Connection.