class TCPSocketMaster
😱 Types incomplete or incorrect? 🙏 Please contribute!
methods
TCPSocketMaster.bind
Binds a master object to address and port on the local host.
Address can be an IP address or a host name. Port must be an integer number in the range [0..64K). If address is '*'
, the system binds to all local interfaces using the INADDR_ANY
constant or IN6ADDR_ANY_INIT
, according to the family. If port
is 0
, the system automatically chooses an ephemeral port.
In case of success, the method returns 1
. In case of error, the method returns nil
followed by an error message.
On success, the type changes to TCPSocketServer
, and you should cast it as such.
Note: The function socket.bind
is available and is a shortcut for the creation of server sockets.
TCPSocketMaster.close
Closes a TCP object. The internal socket used by the object is closed and the local address to which the object was bound is made available to other applications. No further operations (except for further calls to the close method) are allowed on a closed socket.
Note: It is important to close all used sockets once they are not needed, since, in many systems, each socket uses a file descriptor, which are limited system resources. Garbage-collected objects are automatically closed before destruction, though. 😱 Types incomplete or incorrect? 🙏 Please contribute!
TCPSocketMaster.connect
@param
address
- IP address or a host name
@param port
- TCP port, in the range [1..64K)
@return - In case of error, the method returns nil followed by a string describing the error. In case of success, the method returns 1. 😱 Types incomplete or incorrect? 🙏 Please contribute!
@return - In case of error, the method returns nil followed by a string describing the error. In case of success, the method returns 1. 😱 Types incomplete or incorrect? 🙏 Please contribute!
Attempts to connect a master object to a remote host, transforming it into a client object.
Client objects support methods send
, receive
, getsockname
, getpeername
, settimeout
, and close
.
On success, the type changes to TCPClient
, and you should cast it as such.
Note: The function socket.connect
is available and is a shortcut for the creation of client sockets.
Note: Starting with LuaSocket 2.0, the settimeout
method affects the behavior of connect, causing it to return with an error in case of a timeout. If that happens, you can still call socket.select with the socket in the sendt table. The socket will be writable when the connection is established.
Note: Starting with LuaSocket 3.0, the host name resolution depends on whether the socket was created by socket.tcp, socket.tcp4 or socket.tcp6. Addresses from the appropriate family (or both) are tried in the order returned by the resolver until the first success or until the last failure. If the timeout was set to zero, only the first address is tried.
TCPSocketMaster.dirty
@return - true
if there is any data in the read buffer, false
otherwise.
😱 Types incomplete or incorrect? 🙏 Please contribute!
Check the read buffer status.
Note: This is an internal method, use at your own risk.
TCPSocketMaster.getfd
@return - The descriptor or handle. -1
if the object has been closed. _SOCKETINVALID
if it is an invalid socket.
😱 Types incomplete or incorrect? 🙏 Please contribute!
Get the underling socket descriptor or handle associated to the object.
Note: This is an internal method. Unlikely to be portable. use at your own risk.
TCPSocketMaster.getsockname
@return - The IP address of the peer, the port number that the peer is using for the connection, and the family. In case of error, returns nil
.
😱 Types incomplete or incorrect? 🙏 Please contribute!
@return - The IP address of the peer, the port number that the peer is using for the connection, and the family. In case of error, returns nil
.
😱 Types incomplete or incorrect? 🙏 Please contribute!
@return - The IP address of the peer, the port number that the peer is using for the connection, and the family. In case of error, returns nil
.
😱 Types incomplete or incorrect? 🙏 Please contribute!
Returns the local address information associated to the object.
TCPSocketMaster.gettimeout
@return - Current block timeout, current total timeout.
😱 Types incomplete or incorrect? 🙏 Please contribute!
@return - Current block timeout, current total timeout.
😱 Types incomplete or incorrect? 🙏 Please contribute!
Returns the current block timeout followed by the current total timeout.
TCPSocketMaster.listen
@param
backlog
- The number number of client connections that can be queued waiting for service. If the queue is full and another client attempts connection, the connection is refused.
@return - Returns 1 on success, nil and an error on failure.
😱 Types incomplete or incorrect? 🙏 Please contribute!
@return - Returns 1 on success, nil and an error on failure.
😱 Types incomplete or incorrect? 🙏 Please contribute!
Specifies the socket is willing to receive connections, transforming the object into a server object. Server objects support the accept
, getsockname
, setoption
, settimeout
, and close
methods.
On success, the type changes to TCPSocketServer
, and you should cast it as such.
TCPSocketMaster.setstats
@param
received
- Bytes received
@param sent
- Byte sent
@param age
- Age in seconds
@return - 1 on success, nil otherwise. 😱 Types incomplete or incorrect? 🙏 Please contribute!
Resets accounting information on the socket, useful for throttling of bandwidth.
TCPSocketMaster.settimeout
@param
value
- Time to wait, in seconds. Use nil
or negative to block indefinitely.
@param mode
- The default mode is "b"
😱 Types incomplete or incorrect? 🙏 Please contribute!
Changes the timeout values for the object. By default, all I/O operations are blocking. That is, any call to the methods send
, receive
, and accept
will block indefinitely, until the operation completes. The settimeout
method defines a limit on the amount of time the I/O methods can block. When a timeout is set and the specified amount of time has elapsed, the affected methods give up and fail with an error code.
Note: although timeout values have millisecond precision in LuaSocket, large blocks can cause I/O functions not to respect timeout values due to the time the library takes to transfer blocks to and from the OS and to and from the Lua interpreter. Also, function that accept host names and perform automatic name resolution might be blocked by the resolver for longer than the specified timeout value.
Note: The old timeout method is deprecated. The name has been changed for sake of uniformity, since all other method names already contained verbs making their imperative nature obvious.
TCPSocketMaster.setfd
Sets the underling socket descriptor or handle associated to the object. The current one is simply replaced, not closed, and no other change to the object state is made. To set it as invalid use _SOCKETINVALID
.
Note: This is an internal method. Unlikely to be portable. Use at your own risk.