v2026.10.3
All Bundles
Bundle

Provides network support

TCPSocketServer

TCP/IP Server socket

Operations

Accept #

Accepts a client connection

method : public : Accept() ~ TCPSocket

Return

TypeDescription
TCPSocketclient socket interface

Close #

Closes the server socket

method : public : Close() ~ Nil

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 #

Gets the port this server is bound to: the port given to New, or, for a port of 0, the one the system chose at New. A server bound to port 0 takes a free port, so a program (a test, say) needs no fixed number and no two programs can collide; the port is read back here.

method : public : GetPort() ~ Int

Return

TypeDescription
Intbound port, or 0 if the bind failed

Example

server := TCPSocketServer->New(0);
port := server->GetPort(); # the port the system chose

Listen #

Listens for incoming client connections

method : public : Listen(backlog:Int) ~ Bool

Parameters

NameTypeDescription
backlogIntmaximum length to queue pending connections

Return

TypeDescription
Booltrue if client successfully connects, false otherwise

New # constructor

Default constructor

New(port:Int)

Parameters

NameTypeDescription
portIntserver port

New # constructor

Constructor that binds one local address instead of every interface. The address is a literal, such as "127.0.0.1" or "::1", or a host name such as "localhost". A name that resolves to several addresses binds one: its first IPv4 address, else its first IPv6 one, so "localhost" binds 127.0.0.1 on every platform. An IPv6 address takes IPv6 clients only. An empty or Nil address binds every interface, IPv4 and IPv6, as New(port) does. If the address cannot be bound (an unknown name, an address this machine does not have, a port in use), Listen() returns false and GetLastError() says why.

New(address:String, port:Int)

Parameters

NameTypeDescription
addressStringlocal address to bind
portIntserver port