Socket functions
The following socket functions are supported. Socket handles can be used with file I/O functions. See also chapter File functions.
Function/Arguments | Return | Description |
---|---|---|
fsockopen (string hostname, number port, number rcvTimeout=0, bool forceIPV4=false) | handle | Open a TCP/IP client socket and connect to a specified hostname (or ip) and port. Optional parameter rcvTimeout set the timeout in milliseconds data should be received from socket (0=no timeout). If optional parameter forceIPV4 is true then a IPV4 socket will be connected, otherwise IPV6 is preferred. On success the socket handle is returned, otherwise false is returned and a warning is shown. |
fsockserver (string hostname, number port, number backlog=10, bool forceIPV4=false) | handle | Bind a TCP/IP server socket on a specified hostname (or ip) and port and listen for connections. If port is 0 then the next free port number is used, see also fsockport(). The optional backlog parameter set the number of possible waiting clients in background. If optional parameter forceIPV4 is true then a IPV4 socket will be bound, otherwise IPV6 is preferred. On success the socket handle is returned. On errors false is returned. |
fsockaccept (handle socket, number rcvTimeout=0) | handle | Accept a new connection on a TCP/IP server socket. Optional parameter rcvTimeout set the timeout in milliseconds data should be received from new client socket (0=no timeout). On success the socket handle of the new client is returned. On errors false is returned. |
fclose (handle socket) | bool | Shutdown and close a given socket. On success true is returned. |
fsockip (handle socket) | string | Return the IP address of a given socket. |
fsockport (handle socket) | number | Return the port number of a given socket. |
fsockipv6 (handle socket) | bool | Return true if socket is conncted or bound to a IPV6 address. |
gethostbyaddr (string ipaddress) | string | Lookup the hostname of a ipaddress. It can be a IPV4 or IPV6 address. On success the hostname is returned, otherwise false is returned. |
gethostbyname (string hostname, number type=0) | string | Lookup the IP address of a hostname. Optional parameter type marks the type of the IP address: 0 = IPV4 (default), 1 = IPV6. On success the IP address is returned as string, otherwise false is returned. |
Socket I/O functions:
Function/Arguments | Return | Description |
---|---|---|
fwrite (handle socket, string string [, number length]) | number | Write a string into the given socket . If parameter length is not given then the full string is written, otherwise the specified number of bytes are written. On success the number of written bytes is returned. If the peer connection was closed false is returned. |
fread (handle socket, string& string [, number length=0xFFFF]) | number | Read data from the given socket into a string variable. The parameter string must be a reference to a variable. If length is not set then it tries to read 64 KB from the socket. On success the number of read bytes is returned. I the peer connection was closed or timeout occurred false is returned. |
fgets (handle socket) | string | Read a line until Ascii 13=\n from socket . On success the read line is returned. If the peer connection was closed or timeout occurred false is returned. |
freadln (handle socket, string& string) | bool | Read a line until Ascii 13=\n from socket into a given string variable. The parameter string must be a reference to a variable. On success true is returned. If the peer connection was closed or timeout occurred false is returned. |
V1 Version 0.96 - Documentation generated Sun, 05 May 2024 07:59