Version: stable
FUNCTION | |
---|---|
socket.select() | waits for a number of sockets to change status |
socket.tcp6() | creates a new IPv6 TCP master object |
socket.udp6() | creates a new IPv6 UDP object |
socket.dns.tohostname() | resolve to host name (IPv4) |
socket.dns.toip() | resolve to IPv4 address |
socket.dns.gethostname() | gets the machine host name |
socket.dns.getaddrinfo() | resolve to IPv4 or IPv6 address |
socket.dns.getnameinfo() | resolve to hostname (IPv4 or IPv6) |
socket.connect() | creates a new connected TCP client object |
socket.udp() | creates a new IPv4 UDP object |
socket.skip() | drops a number of arguments and returns the remaining |
socket.tcp() | creates a new IPv4 TCP master object |
socket.newtry() | creates a new try function |
socket.protect() | converts a function that throws exceptions into a safe function |
socket.gettime() | gets seconds since system epoch |
socket.sleep() | sleeps for a number of seconds |
server:accept() | waits for a remote connection on the server object |
master:bind() | binds a master object to address and port on the local host |
master:close() | closes a master TCP object |
client:close() | closes a client TCP object |
server:close() | closes a server TCP object |
master:connect() | connects a master object to a remote host |
client:getpeername() | gets information about a client's peer |
master:getsockname() | gets the local address information from master |
client:getsockname() | gets the local address information from client |
server:getsockname() | gets the local address information from server |
master:getstats() | gets accounting information on the socket |
client:getstats() | gets accounting information on the socket |
server:getstats() | gets accounting information on the socket |
master:listen() | makes the master socket listen for connections |
client:receive() | receives data from a client socket |
client:send() | sends data through client socket |
client:setoption() | sets options for the socket |
server:setoption() | sets options for the socket |
client:getoption() | gets options for the socket |
server:getoption() | gets options for the socket |
master:setstats() | resets accounting information on the socket |
client:setstats() | resets accounting information on the socket |
server:setstats() | resets accounting information on the socket |
master:settimeout() | set the timeout values for the socket |
client:settimeout() | set the timeout values for the socket |
server:settimeout() | set the timeout values for the socket |
client:shutdown() | shut down socket |
master:dirty() | checks the read buffer status |
client:dirty() | checks the read buffer status |
server:dirty() | checks the read buffer status |
master:getfd() | gets the socket descriptor |
client:getfd() | gets the socket descriptor |
server:getfd() | gets the socket descriptor |
master:setfd() | sets the socket descriptor |
client:setfd() | sets the socket descriptor |
server:setfd() | sets the socket descriptor |
connected:close() | closes the UDP socket |
unconnected:close() | closes the UDP socket |
connected:getpeername() | gets information about the UDP socket peer |
connected:getsockname() | gets the local address information associated to the socket |
unconnected:getsockname() | gets the local address information associated to the socket |
connected:receive() | receives a datagram from the UDP socket |
unconnected:receive() | receives a datagram from the UDP socket |
unconnected:receivefrom() | receives a datagram from the UDP socket |
connected:getoption() | gets options for the UDP socket |
unconnected:getoption() | gets options for the UDP socket |
connected:send() | sends a datagram through the connected UDP socket |
unconnected:sendto() | sends a datagram through the UDP socket to the specified IP address and port number |
connected:setpeername() | remove the peer of the connected UDP socket |
unconnected:setpeername() | set the peer of the unconnected UDP socket |
unconnected:setsockname() | binds the UDP socket to a local address |
connected:setoption() | sets options for the UDP socket |
unconnected:setoption() | sets options for the UDP socket |
connected:settimeout() | sets the timeout value for the UDP socket |
unconnected:settimeout() | sets the timeout value for the UDP socket |
CONSTANT | |
---|---|
socket._VERSION | the current LuaSocket version |
socket._SETSIZE | max numbers of sockets the select function can handle |
socket.select(recvt,sendt,[timeout])
Recvt
and sendt
parameters can be empty tables or nil
. Non-socket values (or values with non-numeric indices) in these arrays will be silently ignored.
The returned tables are doubly keyed both by integers and also by the sockets themselves, to simplify the test if a specific socket has changed status.
This function can monitor a limited number of sockets, as defined by the constant socket._SETSIZE. This number may be as high as 1024 or as low as 64 by default, depending on the system. It is usually possible to change this at compile time. Invoking select with a larger number of sockets will raise an error.
A known bug in WinSock causes select to fail on non-blocking TCP sockets. The function may return a socket as writable even though the socket is not ready for sending.
Calling select with a server socket in the receive parameter before a call to accept does not guarantee accept will return immediately. Use the settimeout method or accept might block forever.
If you close a socket and pass it to select, it will be ignored.
(Using select with non-socket objects: Any object that implements getfd
and dirty
can be used with select, allowing objects from other libraries to be used within a socket.select driven loop.)
PARAMETERS
recvt |
array with the sockets to test for characters available for reading. |
sendt |
array with sockets that are watched to see if it is OK to immediately write on them. |
[timeout] |
the maximum amount of time (in seconds) to wait for a change in status. Nil, negative or omitted timeout value allows the function to block indefinitely. |
RETURNS
sockets_r |
a list with the sockets ready for reading. |
sockets_w |
a list with the sockets ready for writing. |
error |
an error message. "timeout" if a timeout condition was met, otherwise nil . |
socket.tcp6()
listen
(after a call to bind
) or into a client object with the method connect. The only other method supported by a master object is the close method.
Note: The TCP object returned will have the option "ipv6-v6only" set to true.
PARAMETERS
RETURNS
tcp_master |
a new IPv6 TCP master object, or nil in case of error. |
error |
the error message, or nil if no error occurred. |
socket.udp6()
sendto
, receive
, receivefrom
, getoption
, getsockname
, setoption
, settimeout
, setpeername
, setsockname
, and close
methods. The setpeername
method is used to connect the object.
Note: The UDP object returned will have the option "ipv6-v6only" set to true.
PARAMETERS
RETURNS
udp_unconnected |
a new unconnected IPv6 UDP object, or nil in case of error. |
error |
the error message, or nil if no error occurred. |
socket.dns.tohostname(address)
PARAMETERS
address |
an IPv4 address or host name. |
RETURNS
hostname |
the canonic host name of the given address, or nil in case of an error. |
resolved |
a table with all information returned by the resolver, or if an error occurs, the error message string. |
socket.dns.toip(address)
PARAMETERS
address |
a hostname or an IP address. |
RETURNS
ip_address |
the first IP address found for the hostname, or nil in case of an error. |
resolved |
a table with all information returned by the resolver, or if an error occurs, the error message string. |
socket.dns.gethostname()
PARAMETERS
RETURNS
hostname |
the host name for the machine. |
socket.dns.getaddrinfo(address)
{ [1] = { family = family-name-1, addr = address-1 }, ... [n] = { family = family-name-n, addr = address-n } }
"inet"
for IPv4 addresses, and "inet6"
for IPv6 addresses.
In case of error, the function returns nil followed by an error message.
PARAMETERS
address |
a hostname or an IPv4 or IPv6 address. |
RETURNS
resolved |
a table with all information returned by the resolver, or if an error occurs, nil . |
error |
the error message, or nil if no error occurred. |
socket.dns.getnameinfo(address)
{ [1] = host-name-1, ... [n] = host-name-n, }
PARAMETERS
address |
a hostname or an IPv4 or IPv6 address. |
RETURNS
resolved |
a table with all information returned by the resolver, or if an error occurs, nil . |
error |
the error message, or nil if no error occurred. |
socket.connect(address,port,[locaddr],[locport],[family])
locaddr
and locport
), or restrict the socket family to "inet"
or "inet6"
.
Without specifying family to connect, whether a tcp or tcp6 connection is created depends on
your system configuration.
PARAMETERS
address |
the address to connect to. |
port |
the port to connect to. |
[locaddr] |
optional local address to bind to. |
[locport] |
optional local port to bind to. |
[family] |
optional socket family to use, "inet" or "inet6" . |
RETURNS
tcp_client |
a new IPv6 TCP client object, or nil in case of error. |
error |
the error message, or nil if no error occurred. |
socket.udp()
sendto
, receive
, receivefrom
, getoption
, getsockname
, setoption
, settimeout
, setpeername
, setsockname
, and close
methods. The setpeername
method is used to connect the object.
PARAMETERS
RETURNS
udp_unconnected |
a new unconnected IPv4 UDP object, or nil in case of error. |
error |
the error message, or nil if no error occurred. |
socket.skip(d,[ret1],[ret2],[retN])
D
is the number of arguments to drop. Ret1
to retN
are the arguments.
The function returns retD+1
to retN
.
PARAMETERS
d |
the number of arguments to drop. |
[ret1] |
argument 1. |
[ret2] |
argument 2. |
[retN] |
argument N. |
RETURNS
[retD+1] |
argument D+1. |
[retD+2] |
argument D+2. |
[retN] |
argument N. |
EXAMPLES
Instead of doing the following with dummy variables:-- get the status code and separator from SMTP server reply local dummy1, dummy2, code, sep = string.find(line, "^(%d%d%d)(.?)")
-- get the status code and separator from SMTP server reply local code, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)"))
socket.tcp()
listen
(after a call to bind
) or into a client object with the method connect
. The only other method supported by a master object is the close
method.
PARAMETERS
RETURNS
tcp_master |
a new IPv4 TCP master object, or nil in case of error. |
error |
the error message, or nil if no error occurred. |
socket.newtry(finalizer)
finalizer
function will be called in protected mode (see protect).
PARAMETERS
finalizer |
a function that will be called before the try throws the exception. |
RETURNS
try |
the customized try function. |
EXAMPLES
Perform operations on an open socketc
:
-- create a try function that closes 'c' on error local try = socket.newtry(function() c:close() end) -- do everything reassured c will be closed try(c:send("hello there?\r\n")) local answer = try(c:receive()) ... try(c:send("good bye\r\n")) c:close()
socket.protect(func)
PARAMETERS
func |
a function that calls a try function (or assert, or error) to throw exceptions. |
RETURNS
safe_func |
an equivalent function that instead of throwing exceptions, returns nil followed by an error message. |
EXAMPLES
local dostuff = socket.protect(function() local try = socket.newtry() local c = try(socket.connect("myserver.com", 80)) try = socket.newtry(function() c:close() end) try(c:send("hello?\r\n")) local answer = try(c:receive()) c:close() end) local n, error = dostuff()
socket.gettime()
PARAMETERS
RETURNS
seconds |
the number of seconds elapsed. |
EXAMPLES
How to use the gettime() function to measure running time:t = socket.gettime() -- do stuff print(socket.gettime() - t .. " seconds elapsed")
socket.sleep(time)
PARAMETERS
time |
the number of seconds to sleep for. |
server:accept()
socket.select
with a server object in the recvt
parameter before a call to accept does not guarantee accept will return immediately. Use the settimeout
method or accept might block until another client shows up.
PARAMETERS
RETURNS
tcp_client |
if a connection is successfully initiated, a client object is returned, or nil in case of error. |
error |
the error message, or nil if no error occurred. The error is "timeout" if a timeout condition is met. |
master:bind(address,port)
PARAMETERS
address |
an IP address or a host name. If address is "*" , the system binds to all local interfaces using the INADDR_ANY constant. |
port |
the port to commect to, in the range [0..64K). If port is 0, the system automatically chooses an ephemeral port. |
RETURNS
status |
the value 1 , or nil in case of error. |
error |
the error message, or nil if no error occurred. |
master:close()
PARAMETERS
client:close()
PARAMETERS
server:close()
PARAMETERS
master:connect(address,port)
socket.connect
is available and is a shortcut for the creation of client sockets.
PARAMETERS
address |
an IP address or a host name. If address is "*" , the system binds to all local interfaces using the INADDR_ANY constant. |
port |
the port to commect to, in the range [0..64K). If port is 0, the system automatically chooses an ephemeral port. |
RETURNS
status |
the value 1 , or nil in case of error. |
error |
the error message, or nil if no error occurred. |
client:getpeername()
PARAMETERS
RETURNS
info |
a string with the IP address of the peer, the port number that peer is using for the connection, and the family ("inet" or "inet6"). In case of error, the method returns nil . |
master:getsockname()
PARAMETERS
RETURNS
info |
a string with local IP address, the local port number, and the family ("inet" or "inet6"). In case of error, the method returns nil . |
client:getsockname()
PARAMETERS
RETURNS
info |
a string with local IP address, the local port number, and the family ("inet" or "inet6"). In case of error, the method returns nil . |
server:getsockname()
PARAMETERS
RETURNS
info |
a string with local IP address, the local port number, and the family ("inet" or "inet6"). In case of error, the method returns nil . |
master:getstats()
PARAMETERS
RETURNS
stats |
a string with the number of bytes received, the number of bytes sent, and the age of the socket object in seconds. |
client:getstats()
PARAMETERS
RETURNS
stats |
a string with the number of bytes received, the number of bytes sent, and the age of the socket object in seconds. |
server:getstats()
PARAMETERS
RETURNS
stats |
a string with the number of bytes received, the number of bytes sent, and the age of the socket object in seconds. |
master:listen(backlog)
accept
, getsockname
, setoption
, settimeout
, and close
methods.
PARAMETERS
backlog |
the 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. |
RETURNS
status |
the value 1 , or nil in case of error. |
error |
the error message, or nil if no error occurred. |
client:receive([pattern],[prefix])
read pattern
. Patterns follow the Lua file I/O format, and the difference in performance between patterns is negligible.
PARAMETERS
[pattern] |
the read pattern that can be any of the following:
|
[prefix] |
an optional string to be concatenated to the beginning of any received data before return. |
RETURNS
data |
the received pattern, or nil in case of error. |
error |
the error message, or nil if no error occurred. The error message can be the string "closed" in case the connection was closed before the transmission was completed or the string "timeout" in case there was a timeout during the operation. |
partial |
a (possibly empty) string containing the partial that was received, or nil if no error occurred. |
client:send(data,[i],[j])
..
operator) and send the result in one call instead of calling the method several times.
PARAMETERS
data |
the string to be sent. |
[i] |
optional starting index of the string. |
[j] |
optional end index of string. |
RETURNS
index |
that has been sent, or nil in case of error. Notice that, if i is 1 or absent, this is effectively the total number of bytes sent. |
error |
the error message, or nil if no error occurred. The error message can be "closed" in case the connection was closed before the transmission was completed or the string "timeout" in case there was a timeout during the operation. |
lastindex |
that has been sent. You might want to try again from the byte following that. nil if no error occurred. |
client:setoption(option,[value])
PARAMETERS
option |
the name of the option to set. The value is provided in the value parameter:
timeout has passed. If 'on' is false and a close is issued, the system will process the close in a manner that allows the process to continue as quickly as possible. It is not advised to set this to anything other than zero;
|
[value] |
the value to set for the specified option. |
RETURNS
status |
the value 1 , or nil in case of error. |
error |
the error message, or nil if no error occurred. |
server:setoption(option,[value])
PARAMETERS
option |
the name of the option to set. The value is provided in the value parameter:
timeout has passed. If 'on' is false and a close is issued, the system will process the close in a manner that allows the process to continue as quickly as possible. It is not advised to set this to anything other than zero;
|
[value] |
the value to set for the specified option. |
RETURNS
status |
the value 1 , or nil in case of error. |
error |
the error message, or nil if no error occurred. |
client:getoption(option)
PARAMETERS
option |
the name of the option to get:
|
RETURNS
value |
the option value, or nil in case of error. |
error |
the error message, or nil if no error occurred. |
server:getoption(option)
PARAMETERS
option |
the name of the option to get:
|
RETURNS
value |
the option value, or nil in case of error. |
error |
the error message, or nil if no error occurred. |
master:setstats(received,sent,age)
PARAMETERS
received |
the new number of bytes received. |
sent |
the new number of bytes sent. |
age |
the new age in seconds. |
RETURNS
success |
the value 1 in case of success, or nil in case of error. |
client:setstats(received,sent,age)
PARAMETERS
received |
the new number of bytes received. |
sent |
the new number of bytes sent. |
age |
the new age in seconds. |
RETURNS
success |
the value 1 in case of success, or nil in case of error. |
server:setstats(received,sent,age)
PARAMETERS
received |
the new number of bytes received. |
sent |
the new number of bytes sent. |
age |
the new age in seconds. |
RETURNS
success |
the value 1 in case of success, or nil in case of error. |
master:settimeout(value,[mode])
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.
There are two timeout modes and both can be used together for fine tuning.
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.
PARAMETERS
value |
the amount of time to wait, in seconds. The nil timeout value allows operations to block indefinitely. Negative timeout values have the same effect. |
[mode] |
optional timeout mode to set:
|
client:settimeout(value,[mode])
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.
There are two timeout modes and both can be used together for fine tuning.
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.
PARAMETERS
value |
the amount of time to wait, in seconds. The nil timeout value allows operations to block indefinitely. Negative timeout values have the same effect. |
[mode] |
optional timeout mode to set:
|
server:settimeout(value,[mode])
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.
There are two timeout modes and both can be used together for fine tuning.
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.
PARAMETERS
value |
the amount of time to wait, in seconds. The nil timeout value allows operations to block indefinitely. Negative timeout values have the same effect. |
[mode] |
optional timeout mode to set:
|
client:shutdown(mode)
PARAMETERS
mode |
which way of the connection should be shut down:
|
RETURNS
status |
the value 1 . |
master:dirty()
PARAMETERS
RETURNS
status |
true if there is any data in the read buffer, false otherwise. |
client:dirty()
PARAMETERS
RETURNS
status |
true if there is any data in the read buffer, false otherwise. |
server:dirty()
PARAMETERS
RETURNS
status |
true if there is any data in the read buffer, false otherwise. |
master:getfd()
PARAMETERS
RETURNS
handle |
the descriptor or handle. In case the object has been closed, the return will be -1. |
client:getfd()
PARAMETERS
RETURNS
handle |
the descriptor or handle. In case the object has been closed, the return will be -1. |
server:getfd()
PARAMETERS
RETURNS
handle |
the descriptor or handle. In case the object has been closed, the return will be -1. |
master:setfd(handle)
PARAMETERS
handle |
the descriptor or handle to set. |
client:setfd(handle)
PARAMETERS
handle |
the descriptor or handle to set. |
server:setfd(handle)
PARAMETERS
handle |
the descriptor or handle to set. |
connected:close()
PARAMETERS
unconnected:close()
PARAMETERS
connected:getpeername()
PARAMETERS
RETURNS
info |
a string with the IP address of the peer, the port number that peer is using for the connection, and the family ("inet" or "inet6"). In case of error, the method returns nil . |
connected:getsockname()
setsockname
or the sendto
method is called for the first time (in which case it is bound to an ephemeral port and the wild-card address).
PARAMETERS
RETURNS
info |
a string with local IP address, a number with the local port, and the family ("inet" or "inet6"). In case of error, the method returns nil . |
unconnected:getsockname()
setsockname
or the sendto
method is called for the first time (in which case it is bound to an ephemeral port and the wild-card address).
PARAMETERS
RETURNS
info |
a string with local IP address, a number with the local port, and the family ("inet" or "inet6"). In case of error, the method returns nil . |
connected:receive([size])
PARAMETERS
[size] |
optional maximum size of the datagram to be retrieved. If there are more than size bytes available in the datagram, the excess bytes are discarded. If there are less then size bytes available in the current datagram, the available bytes are returned. If size is omitted, the maximum datagram size is used (which is currently limited by the implementation to 8192 bytes). |
RETURNS
datagram |
the received datagram, or nil in case of error. |
error |
the error message, or nil if no error occurred. |
unconnected:receive([size])
PARAMETERS
[size] |
optional maximum size of the datagram to be retrieved. If there are more than size bytes available in the datagram, the excess bytes are discarded. If there are less then size bytes available in the current datagram, the available bytes are returned. If size is omitted, the maximum datagram size is used (which is currently limited by the implementation to 8192 bytes). |
RETURNS
datagram |
the received datagram, or nil in case of error. |
error |
the error message, or nil if no error occurred. |
unconnected:receivefrom([size])
PARAMETERS
[size] |
optional maximum size of the datagram to be retrieved. |
RETURNS
datagram |
the received datagram, or nil in case of error. |
ip_or_error |
the IP address, or the error message in case of error. |
port |
the port number, or nil in case of error. |
connected:getoption(option)
PARAMETERS
option |
the name of the option to get:
|
RETURNS
value |
the option value, or nil in case of error. |
error |
the error message, or nil if no error occurred. |
unconnected:getoption(option)
PARAMETERS
option |
the name of the option to get:
|
RETURNS
value |
the option value, or nil in case of error. |
error |
the error message, or nil if no error occurred. |
connected:send(datagram)
PARAMETERS
datagram |
a string with the datagram contents. The maximum datagram size for UDP is 64K minus IP layer overhead. However datagrams larger than the link layer packet size will be fragmented, which may deteriorate performance and/or reliability. |
RETURNS
success |
the value 1 on success, or nil in case of error. |
error |
the error message, or nil if no error occurred. |
unconnected:sendto(datagram,ip,port)
PARAMETERS
datagram |
a string with the datagram contents. The maximum datagram size for UDP is 64K minus IP layer overhead. However datagrams larger than the link layer packet size will be fragmented, which may deteriorate performance and/or reliability. |
ip |
the IP address of the recipient. Host names are not allowed for performance reasons. |
port |
the port number at the recipient. |
RETURNS
success |
the value 1 on success, or nil in case of error. |
error |
the error message, or nil if no error occurred. |
connected:setpeername("*")
send
and receive
methods instead of sendto
and receivefrom
.
Since the address of the peer does not have to be passed to and from the OS, the use of connected UDP objects is recommended when the same peer is used for several transmissions and can result in up to 30% performance gains.
PARAMETERS
"*" |
if address is "*" and the object is connected, the peer association is removed and the object becomes an unconnected object again. |
RETURNS
success |
the value 1 on success, or nil in case of error. |
error |
the error message, or nil if no error occurred. |
unconnected:setpeername(address,port)
send
and receive
methods instead of sendto
and receivefrom
.
Since the address of the peer does not have to be passed to and from the OS, the use of connected UDP objects is recommended when the same peer is used for several transmissions and can result in up to 30% performance gains.
PARAMETERS
address |
an IP address or a host name. |
port |
the port number. |
RETURNS
success |
the value 1 on success, or nil in case of error. |
error |
the error message, or nil if no error occurred. |
unconnected:setsockname(address,port)
setsockname
, it cannot be changed.
PARAMETERS
address |
an IP address or a host name. If address is "*" the system binds to all local interfaces using the constant INADDR_ANY . |
port |
the port number. If port is 0, the system chooses an ephemeral port. |
RETURNS
success |
the value 1 on success, or nil in case of error. |
error |
the error message, or nil if no error occurred. |
connected:setoption(option,[value])
PARAMETERS
option |
the name of the option to set. The value is provided in the value parameter:
"ip-add-membership" : Joins the multicast group specified. Receives a table with fields:
|
[value] |
the value to set for the specified option. |
RETURNS
status |
the value 1 , or nil in case of error. |
error |
the error message, or nil if no error occurred. |
unconnected:setoption(option,[value])
PARAMETERS
option |
the name of the option to set. The value is provided in the value parameter:
"ip-add-membership" : Joins the multicast group specified. Receives a table with fields:
|
[value] |
the value to set for the specified option. |
RETURNS
status |
the value 1 , or nil in case of error. |
error |
the error message, or nil if no error occurred. |
connected:settimeout(value)
receive
and receivefrom
operations are blocking. That is, any call to the methods will block indefinitely, until data arrives. The settimeout
function defines a limit on the amount of time the functions 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.
In UDP, the send
and sendto
methods never block (the datagram is just passed to the OS and the call returns immediately). Therefore, the settimeout
method has no effect on them.
PARAMETERS
value |
the amount of time to wait, in seconds. The nil timeout value allows operations to block indefinitely. Negative timeout values have the same effect. |
unconnected:settimeout(value)
receive
and receivefrom
operations are blocking. That is, any call to the methods will block indefinitely, until data arrives. The settimeout
function defines a limit on the amount of time the functions 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.
In UDP, the send
and sendto
methods never block (the datagram is just passed to the OS and the call returns immediately). Therefore, the settimeout
method has no effect on them.
PARAMETERS
value |
the amount of time to wait, in seconds. The nil timeout value allows operations to block indefinitely. Negative timeout values have the same effect. |
the current LuaSocket version
This constant has a string describing the current LuaSocket version.
max numbers of sockets the select function can handle
This constant contains the maximum number of sockets that the select function can handle.