2022-03-22 19:21:58 +01:00
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2004-05-25 08:52:06 +02:00
"http://www.w3.org/TR/html4/strict.dtd">
< html >
< head >
2004-06-21 08:07:58 +02:00
< meta name = "description" content = "LuaSocket: The core namespace" >
2022-03-22 19:21:58 +01:00
< meta name = "keywords" content = "Lua, LuaSocket, Socket, Network, Library, Support" >
2004-06-21 08:07:58 +02:00
< title > LuaSocket: The socket namespace< / title >
2004-05-25 08:52:06 +02:00
< link rel = "stylesheet" href = "reference.css" type = "text/css" >
< / head >
< body >
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2022-03-22 19:21:58 +01:00
< div class = "header" >
2004-05-25 08:52:06 +02:00
< hr >
< center >
< table summary = "LuaSocket logo" >
2022-03-22 19:21:58 +01:00
< tr > < td align = "center" > < a href = "https://www.lua.org" >
< img width = "128" height = "128" border = "0" alt = "LuaSocket" src = "luasocket.png" >
2004-05-25 08:52:06 +02:00
< / a > < / td > < / tr >
2022-03-22 19:21:58 +01:00
< tr > < td align = "center" valign = "top" > Network support for the Lua language
2004-05-25 08:52:06 +02:00
< / td > < / tr >
< / table >
2022-03-22 19:21:58 +01:00
< p class = "bar" >
2009-05-27 11:31:38 +02:00
< a href = "index.html" > home< / a > ·
< a href = "index.html#download" > download< / a > ·
2004-12-13 07:26:01 +01:00
< a href = "installation.html" > installation< / a > ·
2004-05-25 08:52:06 +02:00
< a href = "introduction.html" > introduction< / a > ·
2022-03-22 19:21:58 +01:00
< a href = "reference.html" > reference< / a >
2004-05-25 08:52:06 +02:00
< / p >
< / center >
< hr >
< / div >
<!-- socket +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2022-03-22 19:21:58 +01:00
< h2 id = "socket" > The socket namespace< / h2 >
2004-05-25 08:52:06 +02:00
< p >
2022-03-22 19:21:58 +01:00
The < tt > socket< / tt > namespace contains the core functionality of LuaSocket.
2004-05-25 08:52:06 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p >
2004-06-16 22:41:03 +02:00
To obtain the < tt > socket< / tt > namespace, run:
< / p >
2022-03-22 19:21:58 +01:00
< pre class = "example" >
-- loads the socket module
2004-06-16 22:41:03 +02:00
local socket = require("socket")
< / pre >
2016-03-04 19:36:32 +01:00
<!-- headers.canonic ++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2022-03-22 19:21:58 +01:00
< p class = "name" id = "headers.canonic" >
2016-03-04 19:36:32 +01:00
socket.headers.< b > canonic< / b > < / p >
2022-03-22 19:21:58 +01:00
< p > The < tt > socket.headers.canonic< / tt > table
is used by the HTTP and SMTP modules to translate from
lowercase field names back into their canonic
2016-03-04 19:36:32 +01:00
capitalization. When a lowercase field name exists as a key
in this table, the associated value is substituted in
whenever the field name is sent out.
< / p >
2022-03-22 19:21:58 +01:00
< p >
2016-03-04 19:36:32 +01:00
You can obtain the < tt > headers< / tt > namespace if case run-time
modifications are required by running:
< / p >
2022-03-22 19:21:58 +01:00
< pre class = "example" >
-- loads the headers module
2016-03-04 19:36:32 +01:00
local headers = require("headers")
< / pre >
2004-06-21 00:19:54 +02:00
<!-- bind ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2022-03-22 19:21:58 +01:00
< p class = "name" id = "bind" >
2004-06-21 00:19:54 +02:00
socket.< b > bind(< / b > address, port [, backlog]< b > )< / b >
< / p >
2022-03-22 19:21:58 +01:00
< p class = "description" >
2004-06-21 08:07:58 +02:00
This function is a shortcut that creates and returns a TCP server object
2022-03-22 19:21:58 +01:00
bound to a local < tt > address< / tt > and < tt > port< / tt > , ready to
2004-06-21 08:07:58 +02:00
accept client connections. Optionally,
2022-03-22 19:21:58 +01:00
user can also specify the < tt > backlog< / tt > argument to the
< a href = "tcp.html#listen" > < tt > listen< / tt > < / a > method (defaults to 32).
2004-06-21 08:07:58 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "note" >
Note: The server object returned will have the option "< tt > reuseaddr< / tt > "
2004-06-21 08:07:58 +02:00
set to < tt > < b > true< / b > < / tt > .
2004-06-21 00:19:54 +02:00
< / p >
<!-- connect ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2022-03-22 19:21:58 +01:00
< p class = "name" id = "connect" >
2012-05-10 23:14:22 +02:00
socket.< b > connect[46](< / b > address, port [, locaddr] [, locport] [, family]< b > )< / b >
2004-06-21 00:19:54 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "description" >
2004-06-21 08:07:58 +02:00
This function is a shortcut that creates and returns a TCP client object
2012-05-10 23:14:22 +02:00
connected to a remote < tt > address< / tt > at a given < tt > port< / tt > . Optionally,
2004-06-21 08:07:58 +02:00
the user can also specify the local address and port to bind
2012-05-10 23:14:22 +02:00
(< tt > locaddr< / tt > and < tt > locport< / tt > ), or restrict the socket family
to "< tt > inet< / tt > " or "< tt > inet6< / tt > ".
Without specifying < tt > family< / tt > to < tt > connect< / tt > , whether a tcp or tcp6
connection is created depends on your system configuration. Two variations
of connect are defined as simple helper functions that restrict the
< tt > family< / tt > , < tt > socket.connect4< / tt > and < tt > socket.connect6< / tt > .
2004-06-21 00:19:54 +02:00
< / p >
2004-06-16 22:41:03 +02:00
2004-05-25 08:52:06 +02:00
<!-- debug ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2022-03-22 19:21:58 +01:00
< p class = "name" id = "debug" >
2005-06-14 06:29:23 +02:00
socket.< b > _DEBUG< / b >
2004-05-25 08:52:06 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "description" >
2004-05-25 08:52:06 +02:00
This constant is set to < tt > < b > true< / b > < / tt > if the library was compiled
with debug support.
< / p >
2015-10-06 05:33:50 +02:00
<!-- datagramsize +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2022-03-22 19:21:58 +01:00
< p class = "name" id = "datagramsize" >
2015-10-06 05:33:50 +02:00
socket.< b > _DATAGRAMSIZE< / b >
< / p >
2022-03-22 19:21:58 +01:00
< p class = "description" >
2015-10-06 05:33:50 +02:00
Default datagram size used by calls to
2022-03-22 19:21:58 +01:00
< a href = "udp.html#receive" > < tt > receive< / tt > < / a > and
2015-10-06 05:33:50 +02:00
< a href = "udp.html#receivefrom" > < tt > receivefrom< / tt > < / a > .
(Unless changed in compile time, the value is 8192.)
< / p >
2009-05-27 11:31:38 +02:00
<!-- get time +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2022-03-22 19:21:58 +01:00
< p class = "name" id = "gettime" >
2009-05-27 11:31:38 +02:00
socket.< b > gettime()< / b >
< / p >
2022-03-22 19:21:58 +01:00
< p class = "description" >
2013-11-08 01:13:36 +01:00
Returns the UNIX time in seconds. You should subtract the values returned by this function
2022-03-22 19:21:58 +01:00
to get meaningful values.
2009-05-27 11:31:38 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< pre class = "example" >
2009-05-27 11:31:38 +02:00
t = socket.gettime()
-- do stuff
print(socket.gettime() - t .. " seconds elapsed")
< / pre >
2004-06-18 23:41:51 +02:00
<!-- newtry +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2022-03-22 19:21:58 +01:00
< p class = "name" id = "newtry" >
2004-06-18 23:41:51 +02:00
socket.< b > newtry(< / b > finalizer< b > )< / b >
< / p >
2022-03-22 19:21:58 +01:00
< p class = "description" >
Creates and returns a < em > clean< / em >
2004-06-18 23:41:51 +02:00
< a href = "#try" > < tt > try< / tt > < / a >
2022-03-22 19:21:58 +01:00
function that allows for cleanup before the exception
is raised.
2004-06-18 23:41:51 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "parameters" >
2004-06-18 23:41:51 +02:00
< tt > Finalizer< / tt > is a function that will be called before
2016-02-24 00:48:43 +01:00
< tt > try< / tt > throws the exception.
2004-06-18 23:41:51 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "return" >
The function returns your customized < tt > try< / tt > function.
2004-06-18 23:41:51 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "note" >
Note: This idea saved a < em > lot< / em > of work with the
implementation of protocols in LuaSocket:
2004-06-18 23:41:51 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< pre class = "example" >
2004-06-18 23:41:51 +02:00
foo = socket.protect(function()
-- connect somewhere
local c = socket.try(socket.connect("somewhere", 42))
-- create a try function that closes 'c' on error
local try = socket.newtry(function() c:close() end)
2022-03-22 19:21:58 +01:00
-- do everything reassured c will be closed
2004-12-13 07:26:01 +01:00
try(c:send("hello there?\r\n"))
2004-06-18 23:41:51 +02:00
local answer = try(c:receive())
...
try(c:send("good bye\r\n"))
c:close()
end)
< / pre >
2004-05-25 08:52:06 +02:00
<!-- protect +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2022-03-22 19:21:58 +01:00
< p class = "name" id = "protect" >
2004-06-15 08:24:00 +02:00
socket.< b > protect(< / b > func< b > )< / b >
2004-05-25 08:52:06 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "description" >
2005-02-08 11:01:01 +01:00
Converts a function that throws exceptions into a safe function. This
2022-03-22 19:21:58 +01:00
function only catches exceptions thrown by the < a href = "#try" > < tt > try< / tt > < / a >
and < a href = "#newtry" > < tt > newtry< / tt > < / a > functions. It does not catch normal
2005-02-08 11:01:01 +01:00
Lua errors.
2004-05-25 08:52:06 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "parameters" >
< tt > Func< / tt > is a function that calls
< a href = "#try" > < tt > try< / tt > < / a > (or < tt > assert< / tt > , or < tt > error< / tt > )
to throw exceptions.
2004-05-25 08:52:06 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "return" >
2016-02-24 06:59:37 +01:00
Returns an equivalent function that instead of throwing exceptions in case of
2022-03-22 19:21:58 +01:00
a failed < a href = "#try" > < tt > try< / tt > < / a > call, returns < tt > < b > nil< / b > < / tt >
2016-02-24 06:59:37 +01:00
followed by an error message.
2004-05-25 08:52:06 +02:00
< / p >
2004-05-26 06:58:32 +02:00
<!-- select +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2022-03-22 19:21:58 +01:00
< p class = "name" id = "select" >
2004-05-26 06:58:32 +02:00
socket.< b > select(< / b > recvt, sendt [, timeout]< b > )< / b >
< / p >
2022-03-22 19:21:58 +01:00
< p class = "description" >
Waits for a number of sockets to change status.
2004-05-26 06:58:32 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "parameters" >
2004-05-26 06:58:32 +02:00
< tt > Recvt< / tt > is an array with the sockets to test for characters
available for reading. Sockets in the < tt > sendt< / tt > array are watched to
see if it is OK to immediately write on them. < tt > Timeout< / tt > is the
maximum amount of time (in seconds) to wait for a change in status. A
< tt > < b > nil< / b > < / tt > , negative or omitted < tt > timeout< / tt > value allows the
function to block indefinitely. < tt > Recvt< / tt > and < tt > sendt< / tt > can also
2004-06-16 22:41:03 +02:00
be empty tables or < tt > < b > nil< / b > < / tt > . Non-socket values (or values with
non-numeric indices) in the arrays will be silently ignored.
2004-05-26 06:58:32 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "return" > The function returns a list with the sockets ready for
2007-06-12 01:44:54 +02:00
reading, a list with the sockets ready for writing and an error message.
2016-03-04 18:38:56 +01:00
The error message is "< tt > timeout< / tt > " if a timeout
condition was met, "< tt > select failed< / tt > " if the call
to < tt > select< / tt > failed, and
2007-06-12 01:44:54 +02:00
< tt > < b > nil< / b > < / tt > otherwise. The returned tables are
doubly keyed both by integers and also by the sockets
themselves, to simplify the test if a specific socket has
2022-03-22 19:21:58 +01:00
changed status.
2004-05-26 06:58:32 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "note" >
2016-03-04 18:38:56 +01:00
< b > Note:< / b > < tt > select< / tt > can monitor a limited number
2022-03-22 19:24:38 +01:00
of sockets, as defined by the constant < a href = "#setsize" >
< tt > socket._SETSIZE< / tt > < / a > . This
2009-05-27 11:31:38 +02:00
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 < tt > select< / tt > with a larger
number of sockets will raise an error.
< / p >
2022-03-22 19:21:58 +01:00
< p class = "note" >
< b > Important note< / b > : a known bug in WinSock causes < tt > select< / tt > to fail
2004-05-26 06:58:32 +02:00
on non-blocking TCP sockets. The function may return a socket as
writable even though the socket is < em > not< / em > ready for sending.
< / p >
2022-03-22 19:21:58 +01:00
< p class = "note" >
2004-06-16 03:02:14 +02:00
< b > Another important note< / b > : calling select with a server socket in the receive parameter before a call to accept does < em > not< / em > guarantee
2022-03-22 19:21:58 +01:00
< a href = "tcp.html#accept" > < tt > accept< / tt > < / a > will return immediately.
Use the < a href = "tcp.html#settimeout" > < tt > settimeout< / tt > < / a >
method or < tt > accept< / tt > might block forever.
2004-05-26 06:58:32 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "note" >
2006-04-14 04:04:38 +02:00
< b > Yet another note< / b > : If you close a socket and pass
it to < tt > select< / tt > , it will be ignored.
< / p >
2022-03-22 19:21:58 +01:00
< p class = "note" >
2011-10-24 20:24:58 +02:00
< b > Using select with non-socket objects< / b > : Any object that implements < tt > getfd< / tt > and < tt > dirty< / tt > can be used with < tt > select< / tt > , allowing objects from other libraries to be used within a < tt > socket.select< / tt > driven loop.
< / p >
2016-03-04 19:36:32 +01:00
<!-- setsize ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2022-03-22 19:21:58 +01:00
< p class = "name" id = "setsize" >
2016-03-04 19:36:32 +01:00
socket.< b > _SETSIZE< / b >
< / p >
2022-03-22 19:21:58 +01:00
< p class = "description" >
2016-03-04 19:36:32 +01:00
The maximum number of sockets that the < a
2022-03-22 19:21:58 +01:00
href="#select">< tt > select< / tt > < / a > function can handle.
2016-03-04 19:36:32 +01:00
< / p >
2004-05-26 06:58:32 +02:00
<!-- sink ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2022-03-22 19:21:58 +01:00
< p class = "name" id = "sink" >
2004-05-26 06:58:32 +02:00
socket.< b > sink(< / b > mode, socket< b > )< / b >
< / p >
2022-03-22 19:21:58 +01:00
< p class = "description" >
Creates an
2004-06-15 08:24:00 +02:00
< a href = "http://lua-users.org/wiki/FiltersSourcesAndSinks" > LTN12< / a >
2022-03-22 19:21:58 +01:00
sink from a stream socket object.
2004-05-26 06:58:32 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "parameters" >
2005-11-21 08:04:44 +01:00
< tt > Mode< / tt > defines the behavior of the sink. The following
2004-05-26 06:58:32 +02:00
options are available:
< / p >
< ul >
< li > < tt > "http-chunked"< / tt > : sends data through socket after applying the
2022-03-22 19:21:58 +01:00
< em > chunked transfer coding< / em > , closing the socket when done;< / li >
2004-05-26 06:58:32 +02:00
< li > < tt > "close-when-done"< / tt > : sends all received data through the
2022-03-22 19:21:58 +01:00
socket, closing the socket when done;< / li >
2004-05-26 06:58:32 +02:00
< li > < tt > "keep-open"< / tt > : sends all received data through the
2022-03-22 19:21:58 +01:00
socket, leaving it open when done.< / li >
2004-05-26 06:58:32 +02:00
< / ul >
< p >
2022-03-22 19:21:58 +01:00
< tt > Socket< / tt > is the stream socket object used to send the data.
2004-05-26 06:58:32 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "return" >
The function returns a sink with the appropriate behavior.
2004-05-26 06:58:32 +02:00
< / p >
2004-06-18 10:02:09 +02:00
<!-- skip ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2022-03-22 19:21:58 +01:00
< p class = "name" id = "skip" >
2004-06-18 10:02:09 +02:00
socket.< b > skip(< / b > d [, ret< sub > 1< / sub > , ret< sub > 2< / sub > ... ret< sub > N< / sub > ]< b > )< / b >
< / p >
2022-03-22 19:21:58 +01:00
< p class = "description" >
2004-06-18 10:02:09 +02:00
Drops a number of arguments and returns the remaining.
< / p >
2022-03-22 19:21:58 +01:00
< p class = "parameters" >
2004-06-18 10:02:09 +02:00
< tt > D< / tt > is the number of arguments to drop. < tt > Ret< sub > 1< / sub > < / tt > to
< tt > ret< sub > N< / sub > < / tt > are the arguments.
< / p >
2022-03-22 19:21:58 +01:00
< p class = "return" >
2004-06-18 10:02:09 +02:00
The function returns < tt > ret< sub > d+1< / sub > < / tt > to < tt > ret< sub > N< / sub > < / tt > .
< / p >
2022-03-22 19:21:58 +01:00
< p class = "note" >
2004-06-18 10:02:09 +02:00
Note: This function is useful to avoid creation of dummy variables:
< / p >
2022-03-22 19:21:58 +01:00
< pre class = "example" >
-- get the status code and separator from SMTP server reply
2004-06-18 10:02:09 +02:00
local code, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)"))
< / pre >
<!-- sleep ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2022-03-22 19:21:58 +01:00
< p class = "name" id = "sleep" >
2004-06-18 10:02:09 +02:00
socket.< b > sleep(< / b > time< b > )< / b >
< / p >
2022-03-22 19:21:58 +01:00
< p class = "description" >
2004-06-18 10:02:09 +02:00
Freezes the program execution during a given amount of time.
< / p >
2022-03-22 19:21:58 +01:00
< p class = "parameters" >
2009-05-27 11:31:38 +02:00
< tt > Time< / tt > is the number of seconds to sleep for. If
< tt > time< / tt > is negative, the function returns immediately.
2004-06-18 10:02:09 +02:00
< / p >
2004-05-26 06:58:32 +02:00
<!-- source +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2022-03-22 19:21:58 +01:00
< p class = "name" id = "source" >
2004-05-26 06:58:32 +02:00
socket.< b > source(< / b > mode, socket [, length]< b > )< / b >
< / p >
2022-03-22 19:21:58 +01:00
< p class = "description" >
Creates an
2004-06-15 08:24:00 +02:00
< a href = "http://lua-users.org/wiki/FiltersSourcesAndSinks" > LTN12< / a >
2022-03-22 19:21:58 +01:00
source from a stream socket object.
2004-05-26 06:58:32 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "parameters" >
2004-06-16 06:28:21 +02:00
< tt > Mode< / tt > defines the behavior of the source. The following
2004-05-26 06:58:32 +02:00
options are available:
< / p >
< ul >
< li > < tt > "http-chunked"< / tt > : receives data from socket and removes the
2022-03-22 19:21:58 +01:00
< em > chunked transfer coding< / em > before returning the data;< / li >
2004-05-26 06:58:32 +02:00
< li > < tt > "by-length"< / tt > : receives a fixed number of bytes from the
2022-03-22 19:21:58 +01:00
socket. This mode requires the extra argument < tt > length< / tt > ;< / li >
2004-05-26 06:58:32 +02:00
< li > < tt > "until-closed"< / tt > : receives data from a socket until the other
2022-03-22 19:21:58 +01:00
side closes the connection.< / li >
2004-05-26 06:58:32 +02:00
< / ul >
< p >
2022-03-22 19:21:58 +01:00
< tt > Socket< / tt > is the stream socket object used to receive the data.
2004-05-26 06:58:32 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "return" >
The function returns a source with the appropriate behavior.
2004-05-26 06:58:32 +02:00
< / p >
2015-10-06 05:33:50 +02:00
<!-- socketinvalid ++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2022-03-22 19:21:58 +01:00
< p class = "name" id = "socketinvalid" >
2015-10-06 05:33:50 +02:00
socket.< b > _SOCKETINVALID< / b >
< / p >
2022-03-22 19:21:58 +01:00
< p class = "description" >
2022-03-22 19:24:38 +01:00
The OS value for an invalid socket. This can be used with < a href = "tcp.html#getfd" >
< tt > tcp:getfd< / tt > < / a > and < a href = "tcp.html#setfd" > < tt > tcp:setfd< / tt > < / a > methods.
2015-10-06 05:33:50 +02:00
< / p >
2004-05-26 06:58:32 +02:00
<!-- try ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2004-05-25 08:52:06 +02:00
2022-03-22 19:21:58 +01:00
< p class = "name" id = "try" >
2004-06-16 22:41:03 +02:00
socket.< b > try(< / b > ret< sub > 1< / sub > [, ret< sub > 2< / sub > ... ret< sub > N< / sub > ]< b > )< / b >
2004-05-25 08:52:06 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "description" >
2016-02-24 06:59:37 +01:00
Throws an exception in case < tt > ret< sub > 1< / sub > < / tt > is falsy, using
2022-03-22 19:21:58 +01:00
< tt > ret< sub > 2< / sub > < / tt > as the error message. The exception is supposed to be caught
by a < a href = "#protect" > < tt > protect< / tt > < / a > ed function only.
2004-05-25 08:52:06 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "parameters" >
2004-06-18 10:02:09 +02:00
< tt > Ret< sub > 1< / sub > < / tt > to < tt > ret< sub > N< / sub > < / tt > can be arbitrary
2022-03-22 19:21:58 +01:00
arguments, but are usually the return values of a function call
nested with < tt > try< / tt > .
2004-05-25 08:52:06 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "return" >
2004-06-16 22:41:03 +02:00
The function returns < tt > ret< / tt > < sub > 1< / sub > to < tt > ret< / tt > < sub > N< / sub > if
2016-02-16 09:44:02 +01:00
< tt > ret< / tt > < sub > 1< / sub > is not < tt > < b > nil< / b > < / tt > or < tt > < b > false< / b > < / tt > .
Otherwise, it calls < tt > error< / tt > passing < tt > ret< / tt > < sub > 2< / sub > wrapped
2022-03-22 19:21:58 +01:00
in a table with metatable used by < a href = "#protect" > < tt > protect< / tt > < / a > to
2016-02-16 09:44:02 +01:00
distinguish exceptions from runtime errors.
2004-05-25 08:52:06 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< pre class = "example" >
2004-05-25 08:52:06 +02:00
-- connects or throws an exception with the appropriate error message
c = socket.try(socket.connect("localhost", 80))
< / pre >
2004-06-16 22:41:03 +02:00
<!-- version ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2004-05-25 08:52:06 +02:00
2022-03-22 19:21:58 +01:00
< p class = "name" id = "version" >
2005-06-14 06:29:23 +02:00
socket.< b > _VERSION< / b >
2004-05-25 08:52:06 +02:00
< / p >
2022-03-22 19:21:58 +01:00
< p class = "description" >
This constant has a string describing the current LuaSocket version.
2004-05-25 08:52:06 +02:00
< / p >
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
2022-03-22 19:21:58 +01:00
< div class = "footer" >
2004-05-25 08:52:06 +02:00
< hr >
< center >
2022-03-22 19:21:58 +01:00
< p class = "bar" >
2009-05-27 11:31:38 +02:00
< a href = "index.html" > home< / a > ·
< a href = "index.html#down" > download< / a > ·
2004-12-13 07:26:01 +01:00
< a href = "installation.html" > installation< / a > ·
2004-05-25 08:52:06 +02:00
< a href = "introduction.html" > introduction< / a > ·
< a href = "reference.html" > reference< / a >
< / p >
< p >
< small >
Last modified by Diego Nehab on < br >
2006-04-20 06:27:13 +02:00
Thu Apr 20 00:25:54 EDT 2006
2004-05-25 08:52:06 +02:00
< / small >
< / p >
< / center >
< / div >
< / body >
< / html >