2015-08-23 00:52:01 +02:00
|
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
2003-08-31 03:00:15 +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 TCP/IP support">
|
2015-08-23 00:52:01 +02:00
|
|
|
<meta name="keywords" content="Lua, LuaSocket, Socket, TCP, Library, Network, Support">
|
2004-06-21 08:07:58 +02:00
|
|
|
<title>LuaSocket: TCP/IP support</title>
|
2003-08-31 03:00:15 +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">
|
2003-08-31 03:00:15 +02:00
|
|
|
<hr>
|
|
|
|
<center>
|
|
|
|
<table summary="LuaSocket logo">
|
2022-03-22 19:21:58 +01:00
|
|
|
<tr><td align="center"><a href="http://www.lua.org">
|
|
|
|
<img width="128" height="128" border="0" alt="LuaSocket" src="luasocket.png">
|
2003-08-31 03:00:15 +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
|
2003-08-31 03:00:15 +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> ·
|
2003-08-31 03:00:15 +02:00
|
|
|
<a href="introduction.html">introduction</a> ·
|
2015-08-23 00:52:01 +02:00
|
|
|
<a href="reference.html">reference</a>
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
</center>
|
|
|
|
<hr>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- tcp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
2015-08-23 00:52:01 +02:00
|
|
|
<h2 id="tcp">TCP</h2>
|
2003-08-31 03:00:15 +02:00
|
|
|
|
|
|
|
<!-- accept +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="accept">
|
2003-08-31 03:00:15 +02:00
|
|
|
server:<b>accept()</b>
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2003-08-31 03:00:15 +02:00
|
|
|
Waits for a remote connection on the server
|
|
|
|
object and returns a client object representing that connection.
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="return">
|
2015-08-23 00:52:01 +02:00
|
|
|
If a connection is successfully initiated, a client object is returned.
|
2004-02-04 15:29:11 +01:00
|
|
|
If a timeout condition is met, the method returns <b><tt>nil</tt></b>
|
2015-08-23 00:52:01 +02:00
|
|
|
followed by the error string '<tt>timeout</tt>'. Other errors are
|
2004-02-04 15:29:11 +01:00
|
|
|
reported by <b><tt>nil</tt></b> followed by a message describing the error.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="note">
|
|
|
|
Note: calling <a href="socket.html#select"><tt>socket.select</tt></a>
|
2003-08-31 03:00:15 +02:00
|
|
|
with a server object in
|
2005-08-12 07:56:32 +02:00
|
|
|
the <tt>recvt</tt> parameter before a call to <tt>accept</tt> does
|
2003-08-31 03:00:15 +02:00
|
|
|
<em>not</em> guarantee <tt>accept</tt> will return immediately. Use the <a
|
2022-03-22 19:21:58 +01:00
|
|
|
href="#settimeout"><tt>settimeout</tt></a> method or <tt>accept</tt>
|
2015-08-23 00:52:01 +02:00
|
|
|
might block until <em>another</em> client shows up.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
|
|
|
<!-- bind +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="bind">
|
2004-02-04 15:29:11 +01:00
|
|
|
master:<b>bind(</b>address, port<b>)</b>
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2003-08-31 03:00:15 +02:00
|
|
|
Binds a master object to <tt>address</tt> and <tt>port</tt> on the
|
2015-08-23 00:52:01 +02:00
|
|
|
local host.
|
2022-03-22 19:21:58 +01:00
|
|
|
</p>
|
2003-08-31 03:00:15 +02:00
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="parameters">
|
2015-08-23 00:52:01 +02:00
|
|
|
<tt>Address</tt> can be an IP address or a host name.
|
|
|
|
<tt>Port</tt> must be an integer number in the range [0..64K).
|
2003-08-31 03:00:15 +02:00
|
|
|
If <tt>address</tt>
|
|
|
|
is '<tt>*</tt>', the system binds to all local interfaces
|
2012-08-24 00:31:15 +02:00
|
|
|
using the <tt>INADDR_ANY</tt> constant or
|
2015-08-23 00:52:01 +02:00
|
|
|
<tt>IN6ADDR_ANY_INIT</tt>, according to the family.
|
2012-08-24 00:31:15 +02:00
|
|
|
If <tt>port</tt> is 0, the system automatically
|
2015-08-23 00:52:01 +02:00
|
|
|
chooses an ephemeral port.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="return">
|
2003-08-31 03:00:15 +02:00
|
|
|
In case of success, the method returns 1. In case of error, the
|
2004-01-24 03:47:24 +01:00
|
|
|
method returns <b><tt>nil</tt></b> followed by an error message.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="note">
|
|
|
|
Note: The function <a href="socket.html#bind"><tt>socket.bind</tt></a>
|
2005-08-12 07:56:32 +02:00
|
|
|
is available and is a shortcut for the creation of server sockets.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
|
|
|
<!-- close ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="close">
|
2003-08-31 03:00:15 +02:00
|
|
|
master:<b>close()</b><br>
|
|
|
|
client:<b>close()</b><br>
|
|
|
|
server:<b>close()</b>
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2003-08-31 03:00:15 +02:00
|
|
|
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 <tt>close</tt> method) are allowed on
|
2015-08-23 00:52:01 +02:00
|
|
|
a closed socket.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="note">
|
2003-08-31 03:00:15 +02:00
|
|
|
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
|
2015-08-23 00:52:01 +02:00
|
|
|
automatically closed before destruction, though.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
|
|
|
<!-- connect ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="connect">
|
2003-08-31 03:00:15 +02:00
|
|
|
master:<b>connect(</b>address, port<b>)</b>
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2003-08-31 03:00:15 +02:00
|
|
|
Attempts to connect a master object to a remote host, transforming it into a
|
2015-08-23 00:52:01 +02:00
|
|
|
client object.
|
|
|
|
Client objects support methods
|
2022-03-22 19:21:58 +01:00
|
|
|
<a href="#send"><tt>send</tt></a>,
|
|
|
|
<a href="#receive"><tt>receive</tt></a>,
|
|
|
|
<a href="#getsockname"><tt>getsockname</tt></a>,
|
|
|
|
<a href="#getpeername"><tt>getpeername</tt></a>,
|
|
|
|
<a href="#settimeout"><tt>settimeout</tt></a>,
|
|
|
|
and <a href="#close"><tt>close</tt></a>.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="parameters">
|
2015-08-23 00:52:01 +02:00
|
|
|
<tt>Address</tt> can be an IP address or a host name.
|
|
|
|
<tt>Port</tt> must be an integer number in the range [1..64K).
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="return">
|
2004-01-24 03:47:24 +01:00
|
|
|
In case of error, the method returns <b><tt>nil</tt></b> followed by a string
|
2003-08-31 03:00:15 +02:00
|
|
|
describing the error. In case of success, the method returns 1.
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="note">
|
|
|
|
Note: The function <a href="socket.html#connect"><tt>socket.connect</tt></a>
|
2004-02-04 15:29:11 +01:00
|
|
|
is available and is a shortcut for the creation of client sockets.
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="note">
|
2015-08-23 00:52:01 +02:00
|
|
|
Note: Starting with LuaSocket 2.0,
|
2022-03-22 19:21:58 +01:00
|
|
|
the <a href="#settimeout"><tt>settimeout</tt></a>
|
2015-08-23 00:52:01 +02:00
|
|
|
method affects the behavior of <tt>connect</tt>, causing it to return
|
2005-08-12 07:56:32 +02:00
|
|
|
with an error in case of a timeout. If that happens, you can still call <a
|
2022-03-22 19:21:58 +01:00
|
|
|
href="socket.html#select"><tt>socket.select</tt></a> with the socket in the
|
2005-08-12 07:56:32 +02:00
|
|
|
<tt>sendt</tt> table. The socket will be writable when the connection is
|
2005-11-21 08:04:44 +01:00
|
|
|
established.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="note">
|
2013-06-11 13:10:03 +02:00
|
|
|
Note: Starting with LuaSocket 3.0, the host name resolution
|
2015-12-03 15:56:18 +01:00
|
|
|
depends on whether the socket was created by
|
2022-03-22 19:21:58 +01:00
|
|
|
<a href="#socket.tcp"><tt>socket.tcp</tt></a>,
|
|
|
|
<a href="#socket.tcp4"><tt>socket.tcp4</tt></a> or
|
|
|
|
<a href="#socket.tcp6"><tt>socket.tcp6</tt></a>. Addresses from
|
2015-12-03 15:56:18 +01:00
|
|
|
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.
|
2012-04-16 19:15:26 +02:00
|
|
|
</p>
|
|
|
|
|
2016-03-04 19:36:32 +01:00
|
|
|
<!-- dirty +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="dirty">
|
2016-03-04 19:36:32 +01:00
|
|
|
master:<b>dirty()</b><br>
|
|
|
|
client:<b>dirty()</b><br>
|
|
|
|
server:<b>dirty()</b>
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2016-03-04 19:36:32 +01:00
|
|
|
Check the read buffer status.
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="return">
|
2016-03-04 19:36:32 +01:00
|
|
|
Returns <tt>true</tt> if there is any data in the read buffer, <tt>false</tt> otherwise.
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="note">
|
2016-03-04 19:36:32 +01:00
|
|
|
Note: <b>This is an internal method, use at your own risk.</b>
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- getfd +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="getfd">
|
2016-03-04 19:36:32 +01:00
|
|
|
master:<b>getfd()</b><br>
|
|
|
|
client:<b>getfd()</b><br>
|
|
|
|
server:<b>getfd()</b>
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2016-03-04 19:36:32 +01:00
|
|
|
Returns the underling socket descriptor or handle associated to the object.
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="return">
|
2022-03-22 19:24:38 +01:00
|
|
|
The descriptor or handle. In case the object has been closed, the return value
|
|
|
|
will be -1. For an invalid socket it will be <a href="socket.html#socketinvalid">
|
|
|
|
<tt>_SOCKETINVALID</tt></a>.
|
2016-03-04 19:36:32 +01:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="note">
|
2016-03-04 19:36:32 +01:00
|
|
|
Note: <b>This is an internal method. Unlikely to be
|
|
|
|
portable. Use at your own risk. </b>
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- getoption ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="getoption">
|
|
|
|
client:<b>getoption(option)</b><br>
|
|
|
|
server:<b>getoption(option)</b>
|
2016-03-04 19:36:32 +01:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2016-03-04 19:36:32 +01:00
|
|
|
Gets options for the TCP object.
|
2022-03-22 19:21:58 +01:00
|
|
|
See <a href="#setoption"><tt>setoption</tt></a> for description of the
|
2016-03-04 19:36:32 +01:00
|
|
|
option names and values.
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="parameters">
|
|
|
|
<tt>Option</tt> is a string with the option name.</p>
|
2016-03-04 19:36:32 +01:00
|
|
|
<ul>
|
2022-03-22 19:21:58 +01:00
|
|
|
<li> '<tt>keepalive</tt>'</li>
|
|
|
|
<li> '<tt>linger</tt>'</li>
|
|
|
|
<li> '<tt>reuseaddr</tt>'</li>
|
|
|
|
<li> '<tt>tcp-nodelay</tt>'</li>
|
2016-03-04 19:36:32 +01:00
|
|
|
</ul>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="return">
|
2016-03-04 19:36:32 +01:00
|
|
|
The method returns the option <tt>value</tt> in case of success, or
|
|
|
|
<b><tt>nil</tt></b> followed by an error message otherwise.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
2003-08-31 03:00:15 +02:00
|
|
|
<!-- getpeername ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="getpeername">
|
2003-08-31 03:00:15 +02:00
|
|
|
client:<b>getpeername()</b>
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2003-08-31 03:00:15 +02:00
|
|
|
Returns information about the remote side of a connected client object.
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="return">
|
2015-08-23 00:52:01 +02:00
|
|
|
Returns a string with the IP address of the peer, the
|
|
|
|
port number that peer is using for the connection,
|
|
|
|
and a string with the family ("<tt>inet</tt>" or "<tt>inet6</tt>").
|
|
|
|
In case of error, the method returns <b><tt>nil</tt></b>.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="note">
|
2003-08-31 03:00:15 +02:00
|
|
|
Note: It makes no sense to call this method on server objects.
|
|
|
|
</p>
|
|
|
|
|
2004-07-03 01:31:39 +02:00
|
|
|
<!-- getsockname ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
2003-08-31 03:00:15 +02:00
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="getsockname">
|
2004-06-21 08:07:58 +02:00
|
|
|
master:<b>getsockname()</b><br>
|
2003-08-31 03:00:15 +02:00
|
|
|
client:<b>getsockname()</b><br>
|
|
|
|
server:<b>getsockname()</b>
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2015-08-23 00:52:01 +02:00
|
|
|
Returns the local address information associated to the object.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="return">
|
2015-08-23 00:52:01 +02:00
|
|
|
The method returns a string with local IP address, a number with
|
|
|
|
the local port,
|
|
|
|
and a string with the family ("<tt>inet</tt>" or "<tt>inet6</tt>").
|
2012-04-23 18:47:30 +02:00
|
|
|
In case of error, the method returns <b><tt>nil</tt></b>.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
2004-07-26 06:04:04 +02:00
|
|
|
<!-- getstats +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
2004-07-03 01:31:39 +02:00
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="getstats">
|
2004-07-26 06:04:04 +02:00
|
|
|
master:<b>getstats()</b><br>
|
2004-07-03 01:31:39 +02:00
|
|
|
client:<b>getstats()</b><br>
|
2004-07-26 06:04:04 +02:00
|
|
|
server:<b>getstats()</b><br>
|
2004-07-03 01:31:39 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2004-07-03 01:31:39 +02:00
|
|
|
Returns accounting information on the socket, useful for throttling
|
2015-08-23 00:52:01 +02:00
|
|
|
of bandwidth.
|
2004-07-03 01:31:39 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="return">
|
2004-07-03 01:31:39 +02:00
|
|
|
The method returns the number of bytes received, the number of bytes sent,
|
2015-08-23 00:52:01 +02:00
|
|
|
and the age of the socket object in seconds.
|
2004-07-03 01:31:39 +02:00
|
|
|
</p>
|
|
|
|
|
2016-03-04 19:36:32 +01:00
|
|
|
<!-- gettimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="gettimeout">
|
2016-03-04 19:36:32 +01:00
|
|
|
master:<b>gettimeout()</b><br>
|
|
|
|
client:<b>gettimeout()</b><br>
|
|
|
|
server:<b>gettimeout()</b>
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2016-03-04 19:36:32 +01:00
|
|
|
Returns the current block timeout followed by the curent
|
|
|
|
total timeout.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
2004-02-04 15:29:11 +01:00
|
|
|
<!-- listen ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="listen">
|
2004-02-04 15:29:11 +01:00
|
|
|
master:<b>listen(</b>backlog<b>)</b>
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2004-02-04 15:29:11 +01:00
|
|
|
Specifies the socket is willing to receive connections, transforming the
|
2015-08-23 00:52:01 +02:00
|
|
|
object into a server object. Server objects support the
|
2022-03-22 19:21:58 +01:00
|
|
|
<a href="#accept"><tt>accept</tt></a>,
|
|
|
|
<a href="#getsockname"><tt>getsockname</tt></a>,
|
|
|
|
<a href="#setoption"><tt>setoption</tt></a>,
|
|
|
|
<a href="#settimeout"><tt>settimeout</tt></a>,
|
|
|
|
and <a href="#close"><tt>close</tt></a> methods.
|
2004-02-04 15:29:11 +01:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="parameters">
|
2015-08-23 00:52:01 +02:00
|
|
|
The parameter <tt>backlog</tt> specifies the number of client
|
2004-02-04 15:29:11 +01:00
|
|
|
connections that can
|
|
|
|
be queued waiting for service. If the queue is full and another client
|
|
|
|
attempts connection, the connection is refused.
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="return">
|
2004-02-04 15:29:11 +01:00
|
|
|
In case of success, the method returns 1. In case of error, the
|
|
|
|
method returns <b><tt>nil</tt></b> followed by an error message.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
|
|
|
<!-- receive ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="receive">
|
2004-07-19 00:56:14 +02:00
|
|
|
client:<b>receive(</b>[pattern [, prefix]]<b>)</b>
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2003-08-31 03:00:15 +02:00
|
|
|
Reads data from a client object, according to the specified <em>read
|
2015-08-23 00:52:01 +02:00
|
|
|
pattern</em>. Patterns follow the Lua file I/O format, and the difference in performance between all patterns is negligible.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="parameters">
|
2015-08-23 00:52:01 +02:00
|
|
|
<tt>Pattern</tt> can be any of the following:
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li> '<tt>*a</tt>': reads from the socket until the connection is
|
2022-03-22 19:21:58 +01:00
|
|
|
closed. No end-of-line translation is performed;</li>
|
2003-08-31 03:00:15 +02:00
|
|
|
<li> '<tt>*l</tt>': reads a line of text from the socket. The line is
|
|
|
|
terminated by a LF character (ASCII 10), optionally preceded by a
|
|
|
|
CR character (ASCII 13). The CR and LF characters are not included in
|
2007-10-14 01:55:20 +02:00
|
|
|
the returned line. In fact, <em>all</em> CR characters are
|
2022-03-22 19:21:58 +01:00
|
|
|
ignored by the pattern. This is the default pattern;</li>
|
2015-08-23 00:52:01 +02:00
|
|
|
<li> <tt>number</tt>: causes the method to read a specified <tt>number</tt>
|
2022-03-22 19:21:58 +01:00
|
|
|
of bytes from the socket.</li>
|
2003-08-31 03:00:15 +02:00
|
|
|
</ul>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="parameters">
|
2004-07-19 00:56:14 +02:00
|
|
|
<tt>Prefix</tt> is an optional string to be concatenated to the beginning
|
|
|
|
of any received data before return.
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="return">
|
2004-06-15 08:24:00 +02:00
|
|
|
If successful, the method returns the received pattern. In case of error,
|
2009-05-27 11:31:38 +02:00
|
|
|
the method returns <tt><b>nil</b></tt> followed by an error
|
|
|
|
message, followed by a (possibly empty) string containing
|
|
|
|
the partial that was received. The error message can be
|
|
|
|
the string '<tt>closed</tt>' in case the connection was
|
2004-06-15 08:24:00 +02:00
|
|
|
closed before the transmission was completed or the string
|
|
|
|
'<tt>timeout</tt>' in case there was a timeout during the operation.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="note">
|
2004-06-15 08:24:00 +02:00
|
|
|
<b>Important note</b>: This function was changed <em>severely</em>. It used
|
|
|
|
to support multiple patterns (but I have never seen this feature used) and
|
2015-08-23 00:52:01 +02:00
|
|
|
now it doesn't anymore. Partial results used to be returned in the same
|
2004-06-18 10:02:09 +02:00
|
|
|
way as successful results. This last feature violated the idea that all
|
|
|
|
functions should return <tt><b>nil</b></tt> on error. Thus it was changed
|
2015-08-23 00:52:01 +02:00
|
|
|
too.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
|
|
|
<!-- send +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="send">
|
2004-07-19 00:56:14 +02:00
|
|
|
client:<b>send(</b>data [, i [, j]]<b>)</b>
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2004-07-19 00:56:14 +02:00
|
|
|
Sends <tt>data</tt> through client object.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="parameters">
|
2004-07-19 00:56:14 +02:00
|
|
|
<tt>Data</tt> is the string to be sent. The optional arguments
|
|
|
|
<tt>i</tt> and <tt>j</tt> work exactly like the standard
|
2015-08-23 00:52:01 +02:00
|
|
|
<tt>string.sub</tt> Lua function to allow the selection of a
|
2004-07-19 00:56:14 +02:00
|
|
|
substring to be sent.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="return">
|
2005-11-24 21:29:28 +01:00
|
|
|
If successful, the method returns the index of the last byte
|
|
|
|
within <tt>[i, j]</tt> that has been sent. Notice that, if
|
|
|
|
<tt>i</tt> is 1 or absent, this is effectively the total
|
|
|
|
number of bytes sent. In case of error, the method returns
|
|
|
|
<b><tt>nil</tt></b>, followed by an error message, followed
|
|
|
|
by the index of the last byte within <tt>[i, j]</tt> that
|
|
|
|
has been sent. You might want to try again from the byte
|
|
|
|
following that. The error message can be '<tt>closed</tt>'
|
|
|
|
in case the connection was closed before the transmission
|
|
|
|
was completed or the string '<tt>timeout</tt>' in case
|
|
|
|
there was a timeout during the operation.
|
2004-07-19 00:56:14 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="note">
|
2015-08-23 00:52:01 +02:00
|
|
|
Note: Output is <em>not</em> buffered. For small strings,
|
|
|
|
it is always better to concatenate them in Lua
|
|
|
|
(with the '<tt>..</tt>' operator) and send the result in one call
|
|
|
|
instead of calling the method several times.
|
2004-07-19 00:56:14 +02:00
|
|
|
</p>
|
|
|
|
|
2003-08-31 03:00:15 +02:00
|
|
|
<!-- setoption ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="setoption">
|
2003-08-31 03:00:15 +02:00
|
|
|
client:<b>setoption(</b>option [, value]<b>)</b><br>
|
|
|
|
server:<b>setoption(</b>option [, value]<b>)</b>
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2003-08-31 03:00:15 +02:00
|
|
|
Sets options for the TCP object. Options are only needed by low-level or
|
2015-08-23 00:52:01 +02:00
|
|
|
time-critical applications. You should only modify an option if you
|
|
|
|
are sure you need it.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="parameters">
|
2015-08-23 00:52:01 +02:00
|
|
|
<tt>Option</tt> is a string with the option name, and <tt>value</tt>
|
2022-03-22 19:21:58 +01:00
|
|
|
depends on the option being set:</p>
|
2003-08-31 03:00:15 +02:00
|
|
|
|
|
|
|
<ul>
|
2004-02-04 15:29:11 +01:00
|
|
|
|
|
|
|
<li> '<tt>keepalive</tt>': Setting this option to <tt>true</tt> enables
|
|
|
|
the periodic transmission of messages on a connected socket. Should the
|
|
|
|
connected party fail to respond to these messages, the connection is
|
2022-03-22 19:21:58 +01:00
|
|
|
considered broken and processes using the socket are notified;</li>
|
2004-02-04 15:29:11 +01:00
|
|
|
|
2003-08-31 03:00:15 +02:00
|
|
|
<li> '<tt>linger</tt>': Controls the action taken when unsent data are
|
2003-09-21 22:00:23 +02:00
|
|
|
queued on a socket and a close is performed. The value is a table with a
|
2003-08-31 03:00:15 +02:00
|
|
|
boolean entry '<tt>on</tt>' and a numeric entry for the time interval
|
2004-02-04 15:29:11 +01:00
|
|
|
'<tt>timeout</tt>' in seconds. If the '<tt>on</tt>' field is set to
|
|
|
|
<tt>true</tt>, the system will block the process on the close attempt until
|
|
|
|
it is able to transmit the data or until '<tt>timeout</tt>' has passed. If
|
|
|
|
'<tt>on</tt>' is <tt>false</tt> and a close is issued, the system will
|
|
|
|
process the close in a manner that allows the process to continue as
|
|
|
|
quickly as possible. I do not advise you to set this to anything other than
|
2022-03-22 19:21:58 +01:00
|
|
|
zero;</li>
|
2004-02-04 15:29:11 +01:00
|
|
|
|
|
|
|
<li> '<tt>reuseaddr</tt>': Setting this option indicates that the rules
|
2015-08-23 00:52:01 +02:00
|
|
|
used in validating addresses supplied in a call to
|
2022-03-22 19:21:58 +01:00
|
|
|
<a href="#bind"><tt>bind</tt></a> should allow reuse of local addresses;</li>
|
2004-02-04 15:29:11 +01:00
|
|
|
|
2015-08-23 00:52:01 +02:00
|
|
|
<li> '<tt>tcp-nodelay</tt>': Setting this option to <tt>true</tt>
|
2022-03-22 19:21:58 +01:00
|
|
|
disables the Nagle's algorithm for the connection;</li>
|
2004-02-04 15:29:11 +01:00
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<li> '<tt>tcp-keepidle</tt>': value in seconds for <tt>TCP_KEEPIDLE</tt> Linux only!!</li>
|
2014-12-05 13:17:50 +01:00
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<li> '<tt>tcp-keepcnt</tt>': value for <tt>TCP_KEEPCNT</tt> Linux only!!</li>
|
2014-12-05 13:17:50 +01:00
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<li> '<tt>tcp-keepintvl</tt>': value for <tt>TCP_KEEPINTVL</tt> Linux only!!</li>
|
2014-12-05 13:17:50 +01:00
|
|
|
|
2022-07-27 08:40:18 +02:00
|
|
|
<li> '<tt>tcp-defer-accept</tt>': value for <tt>TCP_DEFER_ACCEPT</tt> Linux only!!</li>
|
|
|
|
|
2022-07-27 08:16:43 +02:00
|
|
|
<li> '<tt>tcp-fastopen</tt>': value for <tt>TCP_FASTOPEN</tt> Linux only!!</li>
|
|
|
|
|
|
|
|
<li> '<tt>tcp-fastopen-connect</tt>': value for <tt>TCP_FASTOPEN_CONNECT</tt> Linux only!!</li>
|
|
|
|
|
2012-04-16 19:15:26 +02:00
|
|
|
<li> '<tt>ipv6-v6only</tt>':
|
|
|
|
Setting this option to <tt>true</tt> restricts an <tt>inet6</tt> socket to
|
2022-03-22 19:21:58 +01:00
|
|
|
sending and receiving only IPv6 packets.</li>
|
2003-08-31 03:00:15 +02:00
|
|
|
</ul>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="return">
|
2012-02-27 22:26:23 +01:00
|
|
|
The method returns 1 in case of success, or <b><tt>nil</tt></b>
|
|
|
|
followed by an error message otherwise.
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="note">
|
2012-02-27 22:26:23 +01:00
|
|
|
Note: The descriptions above come from the man pages.
|
|
|
|
</p>
|
|
|
|
|
2004-07-26 06:04:04 +02:00
|
|
|
<!-- setstats +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="setstats">
|
2004-07-26 06:04:04 +02:00
|
|
|
master:<b>setstats(</b>received, sent, age<b>)</b><br>
|
|
|
|
client:<b>setstats(</b>received, sent, age<b>)</b><br>
|
|
|
|
server:<b>setstats(</b>received, sent, age<b>)</b><br>
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2004-07-26 06:04:04 +02:00
|
|
|
Resets accounting information on the socket, useful for throttling
|
2015-08-23 00:52:01 +02:00
|
|
|
of bandwidth.
|
2004-07-26 06:04:04 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="parameters">
|
2004-07-26 06:04:04 +02:00
|
|
|
<tt>Received</tt> is a number with the new number of bytes received.
|
|
|
|
<tt>Sent</tt> is a number with the new number of bytes sent.
|
2005-08-12 07:56:32 +02:00
|
|
|
<tt>Age</tt> is the new age in seconds.
|
2004-07-26 06:04:04 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="return">
|
2015-08-23 00:52:01 +02:00
|
|
|
The method returns 1 in case of success and <tt><b>nil</b></tt> otherwise.
|
2004-07-26 06:04:04 +02:00
|
|
|
</p>
|
|
|
|
|
2003-08-31 03:00:15 +02:00
|
|
|
<!-- settimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="settimeout">
|
2005-11-20 09:56:19 +01:00
|
|
|
master:<b>settimeout(</b>value [, mode]<b>)</b><br>
|
2003-08-31 03:00:15 +02:00
|
|
|
client:<b>settimeout(</b>value [, mode]<b>)</b><br>
|
|
|
|
server:<b>settimeout(</b>value [, mode]<b>)</b>
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2003-08-31 03:00:15 +02:00
|
|
|
Changes the timeout values for the object. By default,
|
|
|
|
all I/O operations are blocking. That is, any call to the methods
|
2022-03-22 19:21:58 +01:00
|
|
|
<a href="#send"><tt>send</tt></a>,
|
|
|
|
<a href="#receive"><tt>receive</tt></a>, and
|
|
|
|
<a href="#accept"><tt>accept</tt></a>
|
2003-08-31 03:00:15 +02:00
|
|
|
will block indefinitely, until the operation completes. The
|
|
|
|
<tt>settimeout</tt> 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.
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="parameters">
|
2003-08-31 03:00:15 +02:00
|
|
|
The amount of time to wait is specified as the
|
|
|
|
<tt>value</tt> parameter, in seconds. There are two timeout modes and
|
2015-08-23 00:52:01 +02:00
|
|
|
both can be used together for fine tuning:
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li> '<tt>b</tt>': <em>block</em> timeout. Specifies the upper limit on
|
|
|
|
the amount of time LuaSocket can be blocked by the operating system
|
|
|
|
while waiting for completion of any single I/O operation. This is the
|
|
|
|
default mode;</li>
|
|
|
|
|
|
|
|
<li> '<tt>t</tt>': <em>total</em> timeout. Specifies the upper limit on
|
|
|
|
the amount of time LuaSocket can block a Lua script before returning from
|
2015-08-23 00:52:01 +02:00
|
|
|
a call.</li>
|
2003-08-31 03:00:15 +02:00
|
|
|
</ul>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="parameters">
|
2004-01-24 03:47:24 +01:00
|
|
|
The <b><tt>nil</tt></b> timeout <tt>value</tt> allows operations to block
|
2003-08-31 03:00:15 +02:00
|
|
|
indefinitely. Negative timeout values have the same effect.
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="note">
|
2003-08-31 03:00:15 +02:00
|
|
|
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
|
2004-02-04 15:29:11 +01:00
|
|
|
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.
|
2003-08-31 03:00:15 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="note">
|
2003-08-31 03:00:15 +02:00
|
|
|
Note: The old <tt>timeout</tt> 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.
|
|
|
|
</p>
|
|
|
|
|
2004-02-04 15:29:11 +01:00
|
|
|
<!-- shutdown +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="shutdown">
|
2004-02-04 15:29:11 +01:00
|
|
|
client:<b>shutdown(</b>mode<b>)</b><br>
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2015-08-23 00:52:01 +02:00
|
|
|
Shuts down part of a full-duplex connection.
|
2004-02-04 15:29:11 +01:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="parameters">
|
2004-02-04 15:29:11 +01:00
|
|
|
Mode tells which way of the connection should be shut down and can
|
|
|
|
take the value:
|
|
|
|
<ul>
|
|
|
|
<li>"<tt>both</tt>": disallow further sends and receives on the object.
|
2022-03-22 19:21:58 +01:00
|
|
|
This is the default mode;</li>
|
|
|
|
<li>"<tt>send</tt>": disallow further sends on the object;</li>
|
|
|
|
<li>"<tt>receive</tt>": disallow further receives on the object.</li>
|
2004-02-04 15:29:11 +01:00
|
|
|
</ul>
|
2022-03-22 19:21:58 +01:00
|
|
|
</p>
|
2004-02-04 15:29:11 +01:00
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="return">
|
2004-02-04 15:29:11 +01:00
|
|
|
This function returns 1.
|
|
|
|
</p>
|
|
|
|
|
2016-03-04 19:36:32 +01:00
|
|
|
<!-- setfd +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
2011-10-24 20:24:58 +02:00
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="setfd">
|
2016-03-04 19:36:32 +01:00
|
|
|
master:<b>setfd(</b>fd<b>)</b><br>
|
|
|
|
client:<b>setfd(</b>fd<b>)</b><br>
|
|
|
|
server:<b>setfd(</b>fd<b>)</b>
|
2011-10-24 20:24:58 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2022-03-22 19:24:38 +01:00
|
|
|
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 <a href="socket.html#socketinvalid"><tt>_SOCKETINVALID</tt></a>.
|
2011-10-24 20:24:58 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="return">
|
2016-03-04 19:36:32 +01:00
|
|
|
No return value.
|
2011-10-24 20:24:58 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="note">
|
2016-03-04 19:36:32 +01:00
|
|
|
Note: <b>This is an internal method. Unlikely to be
|
|
|
|
portable. Use at your own risk. </b>
|
2011-10-24 20:24:58 +02:00
|
|
|
</p>
|
|
|
|
|
2016-03-04 19:36:32 +01:00
|
|
|
<!-- socket.tcp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
2011-10-24 20:24:58 +02:00
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="socket.tcp">
|
2016-03-04 19:36:32 +01:00
|
|
|
socket.<b>tcp()</b>
|
2011-10-24 20:24:58 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2016-03-04 19:36:32 +01:00
|
|
|
Creates and returns an TCP master object. A master object can
|
|
|
|
be transformed into a server object with the method
|
2022-03-22 19:21:58 +01:00
|
|
|
<a href="#listen"><tt>listen</tt></a> (after a call to <a
|
|
|
|
href="#bind"><tt>bind</tt></a>) or into a client object with
|
|
|
|
the method <a href="#connect"><tt>connect</tt></a>. The only other
|
2016-03-04 19:36:32 +01:00
|
|
|
method supported by a master object is the
|
2022-03-22 19:21:58 +01:00
|
|
|
<a href="#close"><tt>close</tt></a> method.</p>
|
2011-10-24 20:24:58 +02:00
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="return">
|
2016-03-04 19:36:32 +01:00
|
|
|
In case of success, a new master object is returned. In case of error,
|
|
|
|
<b><tt>nil</tt></b> is returned, followed by an error message.
|
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="note">
|
2016-03-04 19:36:32 +01:00
|
|
|
Note: The choice between IPv4 and IPv6 happens during a call to
|
2022-03-22 19:21:58 +01:00
|
|
|
<a href="#bind"><tt>bind</tt></a> or <a
|
|
|
|
href="#bind"><tt>connect</tt></a>, depending on the address
|
2016-03-04 19:36:32 +01:00
|
|
|
family obtained from the resolver.
|
2011-10-24 20:24:58 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="note">
|
2016-03-04 19:36:32 +01:00
|
|
|
Note: Before the choice between IPv4 and IPv6 happens,
|
|
|
|
the internal socket object is invalid and therefore <a
|
2022-03-22 19:21:58 +01:00
|
|
|
href="#setoption"><tt>setoption</tt></a> will fail.
|
2011-10-24 20:24:58 +02:00
|
|
|
</p>
|
|
|
|
|
2016-03-04 19:36:32 +01:00
|
|
|
<!-- socket.tcp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
2011-10-24 20:24:58 +02:00
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="socket.tcp4">
|
2016-03-04 19:36:32 +01:00
|
|
|
socket.<b>tcp4()</b>
|
2011-10-24 20:24:58 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2016-03-04 19:36:32 +01:00
|
|
|
Creates and returns an IPv4 TCP master object. A master object can
|
|
|
|
be transformed into a server object with the method
|
2022-03-22 19:21:58 +01:00
|
|
|
<a href="#listen"><tt>listen</tt></a> (after a call to <a
|
|
|
|
href="#bind"><tt>bind</tt></a>) or into a client object with
|
|
|
|
the method <a href="#connect"><tt>connect</tt></a>. The only other
|
2016-03-04 19:36:32 +01:00
|
|
|
method supported by a master object is the
|
2022-03-22 19:21:58 +01:00
|
|
|
<a href="#close"><tt>close</tt></a> method.</p>
|
2016-03-04 19:36:32 +01:00
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="return">
|
2016-03-04 19:36:32 +01:00
|
|
|
In case of success, a new master object is returned. In case of error,
|
|
|
|
<b><tt>nil</tt></b> is returned, followed by an error message.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<!-- socket.tcp6 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="name" id="socket.tcp6">
|
2016-03-04 19:36:32 +01:00
|
|
|
socket.<b>tcp6()</b>
|
2011-10-24 20:24:58 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="description">
|
2016-03-04 19:36:32 +01:00
|
|
|
Creates and returns an IPv6 TCP master object. A master object can
|
|
|
|
be transformed into a server object with the method
|
2022-03-22 19:21:58 +01:00
|
|
|
<a href="#listen"><tt>listen</tt></a> (after a call to <a
|
|
|
|
href="#bind"><tt>bind</tt></a>) or into a client object with
|
|
|
|
the method <a href="#connect"><tt>connect</tt></a>. The only other
|
2016-03-04 19:36:32 +01:00
|
|
|
method supported by a master object is the
|
2022-03-22 19:21:58 +01:00
|
|
|
<a href="#close"><tt>close</tt></a> method.</p>
|
2016-03-04 19:36:32 +01:00
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="return">
|
2016-03-04 19:36:32 +01:00
|
|
|
In case of success, a new master object is returned. In case of error,
|
|
|
|
<b><tt>nil</tt></b> is returned, followed by an error message.
|
2011-10-24 20:24:58 +02:00
|
|
|
</p>
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<p class="note">
|
2016-03-04 19:36:32 +01:00
|
|
|
Note: The TCP object returned will have the option
|
|
|
|
"<tt>ipv6-v6only</tt>" set to <tt><b>true</b></tt>.
|
2011-10-24 20:24:58 +02:00
|
|
|
</p>
|
|
|
|
|
2016-03-04 19:36:32 +01:00
|
|
|
|
|
|
|
|
2003-08-31 03:00:15 +02:00
|
|
|
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
2022-03-22 19:21:58 +01:00
|
|
|
<div class="footer">
|
2003-08-31 03:00:15 +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> ·
|
2003-08-31 03:00:15 +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:57 EDT 2006
|
2003-08-31 03:00:15 +02:00
|
|
|
</small>
|
|
|
|
</p>
|
|
|
|
</center>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|