Provides network support
TCPSocketServer
TCP/IP Server socket
Operations
Accept #
Accepts a client connection
method : public : Accept() ~ TCPSocketReturn
| Type | Description |
|---|---|
| TCPSocket | client socket interface |
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() ~ StringReturn
| Type | Description |
|---|---|
| String | last 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() ~ IntReturn
| Type | Description |
|---|---|
| Int | bound port, or 0 if the bind failed |
Example
server := TCPSocketServer->New(0);
port := server->GetPort(); # the port the system choseListen #
Listens for incoming client connections
method : public : Listen(backlog:Int) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| backlog | Int | maximum length to queue pending connections |
Return
| Type | Description |
|---|---|
| Bool | true if client successfully connects, false otherwise |
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
| Name | Type | Description |
|---|---|---|
| address | String | local address to bind |
| port | Int | server port |