v2026.11.3
All Bundles
Bundle

Provides network support

UDPSocket

UDP/IP socket

Operations

Close #

Closes the socket

method : public : Close() ~ Nil

Flush #

Flushes the output buffer. This is a no-opt given this socket is not backed by an output buffer.

method : public : Flush() ~ Nil

GetAddress #

Returns the connected network address

method : public : GetAddress() ~ String

Return

TypeDescription
Stringreturn network address

GetLastError # function

Gets the calling thread's last socket failure: why its latest call on a socket -- connect, read, write, bind, listen, accept, a socket option -- failed, captured as it failed. Each such call replaces it, one that works leaves none, and closing the socket keeps it. A connect that tried several addresses gives the most informative reason: one the network answered (refused, reset, timed out) over one that never left this host. A name that does not resolve gives the resolver's reason.

function : GetLastError() ~ String

Return

TypeDescription
Stringlast error message, or Nil if the calling thread's latest socket call worked

GetPort #

Returns the connected network port

method : public : GetPort() ~ Int

Return

TypeDescription
Intreturn network port

New # constructor

A socket connected to one peer: it sends datagrams to the peer and reads the peer's. The address is a host name or an IPv4 or IPv6 literal, resolved as TCPSocket->New resolves it, and a name can resolve to several addresses ("localhost" is ::1 and 127.0.0.1). The socket starts with the first; when the network answers that nobody listens there (an ICMP port unreachable for an earlier datagram), it moves on to the next, so it reaches a server listening on either. When every address has refused, the read or write that found out fails and GetLastError() says "Connection refused". If the name cannot be resolved, GetLastError() says why and the socket sends nothing.

New(address:System.String, port:Int)

Parameters

NameTypeDescription
addressStringnetwork address
portIntnetwork port

ReadBuffer #

Reads bytes into a byte buffer

method : public : ReadBuffer(offset:Int, num:Int, buffer:Byte[]) ~ Int

Parameters

NameTypeDescription
offsetIntdestination buffer offset
numIntnumber of values to read
bufferByteinput buffer

Return

TypeDescription
Intnumber of values read

ReadBuffer #

Reads bytes into a character buffer

method : public : ReadBuffer(offset:Int, num:Int, buffer:Char[]) ~ Int

Parameters

NameTypeDescription
offsetIntdestination buffer offset
numIntnumber of values to read
bufferCharinput buffer

Return

TypeDescription
Intnumber of values read

ReadByte #

Reads a byte

method : public : ReadByte() ~ Byte

Return

TypeDescription
Bytebyte read

ReadLine #

Reads a string until a newline or character return is detected

method : public : ReadLine() ~ System.String

Return

TypeDescription
Stringcharacter string

WriteBuffer #

Writes bytes from a byte buffer

method : public : WriteBuffer(buffer:Byte[]) ~ Int

Parameters

NameTypeDescription
bufferByteinput buffer

Return

TypeDescription
Intnumber of values written

WriteBuffer #

Writes bytes from a byte buffer

method : public : WriteBuffer(offset:Int, num:Int, buffer:Byte[]) ~ Int

Parameters

NameTypeDescription
offsetIntdestination buffer offset
numIntnumber of values to write
bufferByteinput buffer

Return

TypeDescription
Intnumber of values written

WriteBuffer #

Writes characters from a byte buffer

method : public : WriteBuffer(buffer:Char[]) ~ Int

Parameters

NameTypeDescription
bufferCharinput buffer

Return

TypeDescription
Intnumber of values written

WriteBuffer #

Writes characters from a character buffer

method : public : WriteBuffer(offset:Int, num:Int, buffer:Char[]) ~ Int

Parameters

NameTypeDescription
offsetIntdestination buffer offset
numIntnumber of values to write
bufferCharinput buffer

Return

TypeDescription
Intnumber of values written

WriteByte #

Writes a byte

method : public : WriteByte(b:Int) ~ Bool

Parameters

NameTypeDescription
bIntbyte to write

Return

TypeDescription
Booltrue if byte was written, false otherwise

WriteString #

Writes a character string

method : public : WriteString(str:System.String) ~ Nil

Parameters

NameTypeDescription
strStringstring to be written