API Reference › Udp
namespace

Udp

Plain IPv4 datagrams, polled — the transport under a game's own netcode: peer-to-peer play, a LAN lobby, a STUN query. Open a socket with Udp.open, send with Udp.send, and each frame drain what arrived with Udp.recv, which returns 0 when nothing is waiting and never blocks. The sender of the last datagram read is Udp.from_ip / from_port. An address is an int: a.b.c.d is (a << 24) | (b << 16) | (c << 8) | d, converted by Udp.ip and Udp.ip_text. Datagrams can be lost, repeated and reordered; the protocol a game builds on top says what to do about that. Like Http.* it is out-of-band and must never feed the deterministic lockstep/replay simulation directly. BSD sockets on macOS, Winsock on Windows.

Udp.open(port) -> intOpen a socket on a port.Udp.port(socket) -> intThe port a socket is bound to.Udp.send(socket, ip, port, bytes, len) -> intSend one datagram.Udp.recv(socket, bytes, cap) -> intRead the next waiting datagram.Udp.from_ip(socket) -> intThe sender of the last datagram read.Udp.from_port(socket) -> intThe sender's port.Udp.close(socket) -> voidClose a socket.Udp.resolve(name) -> intLook a host name up.Udp.local_ip() -> intThis machine's address.Udp.ip(text) -> intParse a dotted address.Udp.ip_text(ip) -> stringFormat an address.
← All symbols