Skip to content

udp ​

UDP datagram sockets.

Import

ts
import { Udp } from "udp";

Needs the "net" permission in thicket.json.

UdpSender class ​

ts
class UdpSender

Type only: the runtime hands you instances; you never construct it yourself.

Sender address supplied to UDP receive callbacks.

UdpSender.host ​

ts
readonly host: string

Host address (IP) of the sender.

UdpSender.port ​

ts
readonly port: int

Port number of the sender.

UdpSocket class ​

ts
class UdpSocket

Type only: the runtime hands you instances; you never construct it yourself.

A bound or unbound UDP socket.

UdpSocket.sendTo ​

ts
sendTo(host: string, port: int, data: string | ByteArray): void

Send a datagram to a remote address.

Parameters

  • host: Destination host (IP address).
  • port: Destination port (1–65535).
  • data: Payload as string or ByteArray.

UdpSocket.onData ​

ts
onData(fn: (data: string, sender: UdpSender) => void): void

Register a callback to receive datagrams as strings.

Parameters

  • fn: Callback receiving (data: string, sender: UdpSender).

UdpSocket.onBinary ​

ts
onBinary(fn: (data: ByteArray, sender: UdpSender) => void): void

Register a callback to receive datagrams as ByteArray.

Parameters

  • fn: Callback receiving (data: ByteArray, sender: UdpSender).

UdpSocket.port ​

ts
readonly port: int

Local port this socket is bound to. Read-only.

UdpSocket.broadcast ​

ts
broadcast: boolean

Enable or disable broadcast mode.

UdpSocket.close ​

ts
close(): void

Close the socket and stop listening.

Udp static class ​

ts
static class Udp

UDP socket factories.

Udp.bind ​

ts
static bind(port: int, host?: string): UdpSocket

Create and bind a UDP socket to a local address.

Parameters

  • port: Local port to bind to; 0 means the OS assigns an available port.
  • host: Local host/interface to bind to; defaults to all interfaces.

Returns: A bound UdpSocket.

Udp.create ​

ts
static create(): UdpSocket

Create an unbound UDP socket for outbound-only use or later binding.

Returns: An unbound UdpSocket.


Generated from lang/types/udp.d.tks in the ThicketScript repository.