Provides network support
UDPSocketServer
UDP/IP Server socket
Operations
- New
- Bind
- Close
- Flush
- GetLastError
- GetPort
- IsBound
- ReadBuffer
- ReadByte
- ReadLine
- WriteBuffer
- WriteByte
- WriteString
Bind #
Binds the UDP server socket
method : public : Bind() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if successfully bound, false otherwise |
Flush #
Flushes the output buffer. This is a no-opt given this socket is not backed by an output buffer.
method : public : Flush() ~ NilGetLastError # 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 when Bind() bound the socket, so a program needs no fixed port number.
method : public : GetPort() ~ IntReturn
| Type | Description |
|---|---|
| Int | bound port |
IsBound #
Checks if the UDP server socket is bound
method : public : IsBound() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if successfully bound, false otherwise |
New # constructor
A UDP server on a port of every interface, IPv4 and IPv6 alike, as the TCP, TLS and DTLS servers bind. A read takes a datagram from any client, and a write goes to the sender of the last datagram read. A client that has gone does not fail the next read: the server keeps serving the others.
New(port:Int, bind:Bool)Parameters
| Name | Type | Description |
|---|---|---|
| port | Int | server port |
| bind | Bool | bind to port on creation, default is true |
New # constructor
A UDP server bound to one local address instead of every interface, read as TCPSocketServer->New(address, port) reads it: a literal such as "127.0.0.1" or "::1", or a host name, which binds its first IPv4 address, else its first IPv6 one. An IPv6 address takes IPv6 clients only. An empty or Nil address binds every interface, as New(port) does. If the address cannot be bound, IsBound() is false and GetLastError() says why.
New(address:String, port:Int, bind:Bool)Parameters
| Name | Type | Description |
|---|---|---|
| address | String | local address to bind |
| port | Int | server port |
| bind | Bool | bind to the address on creation, default is true |
ReadBuffer #
Reads bytes into a byte buffer
method : public : ReadBuffer(offset:Int, num:Int, buffer:Byte[]) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| offset | Int | destination buffer offset |
| num | Int | number of values to read |
| buffer | Byte | input buffer |
Return
| Type | Description |
|---|---|
| Int | number of values read |
ReadBuffer #
Reads bytes into a character buffer
method : public : ReadBuffer(offset:Int, num:Int, buffer:Char[]) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| offset | Int | destination buffer offset |
| num | Int | number of values to read |
| buffer | Char | input buffer |
Return
| Type | Description |
|---|---|
| Int | number of values read |
ReadLine #
Reads a string until a newline or character return is detected
method : public : ReadLine() ~ System.StringReturn
| Type | Description |
|---|---|
| String | character string |
WriteBuffer #
Writes bytes from a byte buffer
method : public : WriteBuffer(buffer:Byte[]) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| buffer | Byte | input buffer |
Return
| Type | Description |
|---|---|
| Int | number of values written |
WriteBuffer #
Writes bytes from a byte buffer
method : public : WriteBuffer(offset:Int, num:Int, buffer:Byte[]) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| offset | Int | destination buffer offset |
| num | Int | number of values to write |
| buffer | Byte | input buffer |
Return
| Type | Description |
|---|---|
| Int | number of values written |
WriteBuffer #
Writes characters from a byte buffer
method : public : WriteBuffer(buffer:Char[]) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| buffer | Char | input buffer |
Return
| Type | Description |
|---|---|
| Int | number of values written |
WriteBuffer #
Writes characters from a character buffer
method : public : WriteBuffer(offset:Int, num:Int, buffer:Char[]) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| offset | Int | destination buffer offset |
| num | Int | number of values to write |
| buffer | Char | input buffer |
Return
| Type | Description |
|---|---|
| Int | number of values written |