| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| 2 |
"http://www.w3.org/TR/html4/strict.dtd"> |
| 3 |
<html> |
| 4 |
|
| 5 |
<head> |
| 6 |
<meta name="description" content="LuaSocket: The TCP/IP support"> |
| 7 |
<meta name="keywords" content="Lua, LuaSocket, Socket, TCP, Library, Network, Support"> |
| 8 |
<title>LuaSocket: TCP/IP support</title> |
| 9 |
<link rel="stylesheet" href="reference.css" type="text/css"> |
| 10 |
</head> |
| 11 |
|
| 12 |
<body> |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
<div class=header> |
| 17 |
<hr> |
| 18 |
<center> |
| 19 |
<table summary="LuaSocket logo"> |
| 20 |
<tr><td align=center><a href="http://www.lua.org"> |
| 21 |
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png"> |
| 22 |
</a></td></tr> |
| 23 |
<tr><td align=center valign=top>Network support for the Lua language |
| 24 |
</td></tr> |
| 25 |
</table> |
| 26 |
<p class=bar> |
| 27 |
<a href="index.html">home</a> · |
| 28 |
<a href="index.html#download">download</a> · |
| 29 |
<a href="installation.html">installation</a> · |
| 30 |
<a href="introduction.html">introduction</a> · |
| 31 |
<a href="reference.html">reference</a> |
| 32 |
</p> |
| 33 |
</center> |
| 34 |
<hr> |
| 35 |
</div> |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
<h2 id="tcp">TCP</h2> |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
<p class=name id="accept"> |
| 44 |
server:<b>accept()</b> |
| 45 |
</p> |
| 46 |
|
| 47 |
<p class=description> |
| 48 |
Waits for a remote connection on the server |
| 49 |
object and returns a client object representing that connection. |
| 50 |
</p> |
| 51 |
|
| 52 |
<p class=return> |
| 53 |
If a connection is successfully initiated, a client object is returned. |
| 54 |
If a timeout condition is met, the method returns <b><tt>nil</tt></b> |
| 55 |
followed by the error string '<tt>timeout</tt>'. Other errors are |
| 56 |
reported by <b><tt>nil</tt></b> followed by a message describing the error. |
| 57 |
</p> |
| 58 |
|
| 59 |
<p class=note> |
| 60 |
Note: calling <a href=socket.html#select><tt>socket.select</tt></a> |
| 61 |
with a server object in |
| 62 |
the <tt>recvt</tt> parameter before a call to <tt>accept</tt> does |
| 63 |
<em>not</em> guarantee <tt>accept</tt> will return immediately. Use the <a |
| 64 |
href=#settimeout><tt>settimeout</tt></a> method or <tt>accept</tt> |
| 65 |
might block until <em>another</em> client shows up. |
| 66 |
</p> |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
<p class=name id="bind"> |
| 71 |
master:<b>bind(</b>address, port<b>)</b> |
| 72 |
</p> |
| 73 |
|
| 74 |
<p class=description> |
| 75 |
Binds a master object to <tt>address</tt> and <tt>port</tt> on the |
| 76 |
local host. |
| 77 |
|
| 78 |
<p class=parameters> |
| 79 |
<tt>Address</tt> can be an IP address or a host name. |
| 80 |
<tt>Port</tt> must be an integer number in the range [0..64K). |
| 81 |
If <tt>address</tt> |
| 82 |
is '<tt>*</tt>', the system binds to all local interfaces |
| 83 |
using the <tt>INADDR_ANY</tt> constant or |
| 84 |
<tt>IN6ADDR_ANY_INIT</tt>, according to the family. |
| 85 |
If <tt>port</tt> is 0, the system automatically |
| 86 |
chooses an ephemeral port. |
| 87 |
</p> |
| 88 |
|
| 89 |
<p class=return> |
| 90 |
In case of success, the method returns 1. In case of error, the |
| 91 |
method returns <b><tt>nil</tt></b> followed by an error message. |
| 92 |
</p> |
| 93 |
|
| 94 |
<p class=note> |
| 95 |
Note: The function <a href=socket.html#bind><tt>socket.bind</tt></a> |
| 96 |
is available and is a shortcut for the creation of server sockets. |
| 97 |
</p> |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
<p class=name id="close"> |
| 102 |
master:<b>close()</b><br> |
| 103 |
client:<b>close()</b><br> |
| 104 |
server:<b>close()</b> |
| 105 |
</p> |
| 106 |
|
| 107 |
<p class=description> |
| 108 |
Closes a TCP object. The internal socket used by the object is closed |
| 109 |
and the local address to which the object was |
| 110 |
bound is made available to other applications. No further operations |
| 111 |
(except for further calls to the <tt>close</tt> method) are allowed on |
| 112 |
a closed socket. |
| 113 |
</p> |
| 114 |
|
| 115 |
<p class=note> |
| 116 |
Note: It is important to close all used sockets once they are not |
| 117 |
needed, since, in many systems, each socket uses a file descriptor, |
| 118 |
which are limited system resources. Garbage-collected objects are |
| 119 |
automatically closed before destruction, though. |
| 120 |
</p> |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
<p class=name id="connect"> |
| 125 |
master:<b>connect(</b>address, port<b>)</b> |
| 126 |
</p> |
| 127 |
|
| 128 |
<p class=description> |
| 129 |
Attempts to connect a master object to a remote host, transforming it into a |
| 130 |
client object. |
| 131 |
Client objects support methods |
| 132 |
<a href=#send><tt>send</tt></a>, |
| 133 |
<a href=#receive><tt>receive</tt></a>, |
| 134 |
<a href=#getsockname><tt>getsockname</tt></a>, |
| 135 |
<a href=#getpeername><tt>getpeername</tt></a>, |
| 136 |
<a href=#settimeout><tt>settimeout</tt></a>, |
| 137 |
and <a href=#close><tt>close</tt></a>. |
| 138 |
</p> |
| 139 |
|
| 140 |
<p class=parameters> |
| 141 |
<tt>Address</tt> can be an IP address or a host name. |
| 142 |
<tt>Port</tt> must be an integer number in the range [1..64K). |
| 143 |
</p> |
| 144 |
|
| 145 |
<p class=return> |
| 146 |
In case of error, the method returns <b><tt>nil</tt></b> followed by a string |
| 147 |
describing the error. In case of success, the method returns 1. |
| 148 |
</p> |
| 149 |
|
| 150 |
<p class=note> |
| 151 |
Note: The function <a href=socket.html#connect><tt>socket.connect</tt></a> |
| 152 |
is available and is a shortcut for the creation of client sockets. |
| 153 |
</p> |
| 154 |
|
| 155 |
<p class=note> |
| 156 |
Note: Starting with LuaSocket 2.0, |
| 157 |
the <a href=#settimeout><tt>settimeout</tt></a> |
| 158 |
method affects the behavior of <tt>connect</tt>, causing it to return |
| 159 |
with an error in case of a timeout. If that happens, you can still call <a |
| 160 |
href=socket.html#select><tt>socket.select</tt></a> with the socket in the |
| 161 |
<tt>sendt</tt> table. The socket will be writable when the connection is |
| 162 |
established. |
| 163 |
</p> |
| 164 |
|
| 165 |
<p class=note> |
| 166 |
Note: Starting with LuaSocket 3.0, the host name resolution |
| 167 |
depends on whether the socket was created by |
| 168 |
<a href=#socket.tcp><tt>socket.tcp</tt></a>, |
| 169 |
<a href=#socket.tcp4><tt>socket.tcp4</tt></a> or |
| 170 |
<a href=#socket.tcp6><tt>socket.tcp6</tt></a>. Addresses from |
| 171 |
the appropriate family (or both) are tried in the order |
| 172 |
returned by the resolver until the |
| 173 |
first success or until the last failure. If the timeout was |
| 174 |
set to zero, only the first address is tried. |
| 175 |
</p> |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
<p class=name id="dirty"> |
| 180 |
master:<b>dirty()</b><br> |
| 181 |
client:<b>dirty()</b><br> |
| 182 |
server:<b>dirty()</b> |
| 183 |
</p> |
| 184 |
|
| 185 |
<p class=description> |
| 186 |
Check the read buffer status. |
| 187 |
</p> |
| 188 |
|
| 189 |
<p class=return> |
| 190 |
Returns <tt>true</tt> if there is any data in the read buffer, <tt>false</tt> otherwise. |
| 191 |
</p> |
| 192 |
|
| 193 |
<p class=note> |
| 194 |
Note: <b>This is an internal method, use at your own risk.</b> |
| 195 |
</p> |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
<p class=name id="getfd"> |
| 201 |
master:<b>getfd()</b><br> |
| 202 |
client:<b>getfd()</b><br> |
| 203 |
server:<b>getfd()</b> |
| 204 |
</p> |
| 205 |
|
| 206 |
<p class=description> |
| 207 |
Returns the underling socket descriptor or handle associated to the object. |
| 208 |
</p> |
| 209 |
|
| 210 |
<p class=return> |
| 211 |
The descriptor or handle. In case the object has been closed, the return will be -1. |
| 212 |
</p> |
| 213 |
|
| 214 |
<p class=note> |
| 215 |
Note: <b>This is an internal method. Unlikely to be |
| 216 |
portable. Use at your own risk. </b> |
| 217 |
</p> |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
<p class=name id="getoption"> |
| 223 |
client:<b>getoption(</b>option)</b><br> |
| 224 |
server:<b>getoption(</b>option)</b> |
| 225 |
</p> |
| 226 |
|
| 227 |
<p class=description> |
| 228 |
Gets options for the TCP object. |
| 229 |
See <a href=#setoption><tt>setoption</tt></a> for description of the |
| 230 |
option names and values. |
| 231 |
</p> |
| 232 |
|
| 233 |
<p class=parameters> |
| 234 |
<tt>Option</tt> is a string with the option name. |
| 235 |
<ul> |
| 236 |
|
| 237 |
<li> '<tt>keepalive</tt>' |
| 238 |
<li> '<tt>linger</tt>' |
| 239 |
<li> '<tt>reuseaddr</tt>' |
| 240 |
<li> '<tt>tcp-nodelay</tt>' |
| 241 |
</ul> |
| 242 |
|
| 243 |
<p class=return> |
| 244 |
The method returns the option <tt>value</tt> in case of success, or |
| 245 |
<b><tt>nil</tt></b> followed by an error message otherwise. |
| 246 |
</p> |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
<p class=name id="getpeername"> |
| 252 |
client:<b>getpeername()</b> |
| 253 |
</p> |
| 254 |
|
| 255 |
<p class=description> |
| 256 |
Returns information about the remote side of a connected client object. |
| 257 |
</p> |
| 258 |
|
| 259 |
<p class=return> |
| 260 |
Returns a string with the IP address of the peer, the |
| 261 |
port number that peer is using for the connection, |
| 262 |
and a string with the family ("<tt>inet</tt>" or "<tt>inet6</tt>"). |
| 263 |
In case of error, the method returns <b><tt>nil</tt></b>. |
| 264 |
</p> |
| 265 |
|
| 266 |
<p class=note> |
| 267 |
Note: It makes no sense to call this method on server objects. |
| 268 |
</p> |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
<p class=name id="getsockname"> |
| 273 |
master:<b>getsockname()</b><br> |
| 274 |
client:<b>getsockname()</b><br> |
| 275 |
server:<b>getsockname()</b> |
| 276 |
</p> |
| 277 |
|
| 278 |
<p class=description> |
| 279 |
Returns the local address information associated to the object. |
| 280 |
</p> |
| 281 |
|
| 282 |
<p class=return> |
| 283 |
The method returns a string with local IP address, a number with |
| 284 |
the local port, |
| 285 |
and a string with the family ("<tt>inet</tt>" or "<tt>inet6</tt>"). |
| 286 |
In case of error, the method returns <b><tt>nil</tt></b>. |
| 287 |
</p> |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
<p class=name id="getstats"> |
| 292 |
master:<b>getstats()</b><br> |
| 293 |
client:<b>getstats()</b><br> |
| 294 |
server:<b>getstats()</b><br> |
| 295 |
</p> |
| 296 |
|
| 297 |
<p class=description> |
| 298 |
Returns accounting information on the socket, useful for throttling |
| 299 |
of bandwidth. |
| 300 |
</p> |
| 301 |
|
| 302 |
<p class=return> |
| 303 |
The method returns the number of bytes received, the number of bytes sent, |
| 304 |
and the age of the socket object in seconds. |
| 305 |
</p> |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
<p class=name id="gettimeout"> |
| 310 |
master:<b>gettimeout()</b><br> |
| 311 |
client:<b>gettimeout()</b><br> |
| 312 |
server:<b>gettimeout()</b> |
| 313 |
</p> |
| 314 |
|
| 315 |
<p class=description> |
| 316 |
Returns the current block timeout followed by the curent |
| 317 |
total timeout. |
| 318 |
</p> |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
<p class=name id="listen"> |
| 324 |
master:<b>listen(</b>backlog<b>)</b> |
| 325 |
</p> |
| 326 |
|
| 327 |
<p class=description> |
| 328 |
Specifies the socket is willing to receive connections, transforming the |
| 329 |
object into a server object. Server objects support the |
| 330 |
<a href=#accept><tt>accept</tt></a>, |
| 331 |
<a href=#getsockname><tt>getsockname</tt></a>, |
| 332 |
<a href=#setoption><tt>setoption</tt></a>, |
| 333 |
<a href=#settimeout><tt>settimeout</tt></a>, |
| 334 |
and <a href=#close><tt>close</tt></a> methods. |
| 335 |
</p> |
| 336 |
|
| 337 |
<p class=parameters> |
| 338 |
The parameter <tt>backlog</tt> specifies the number of client |
| 339 |
connections that can |
| 340 |
be queued waiting for service. If the queue is full and another client |
| 341 |
attempts connection, the connection is refused. |
| 342 |
</p> |
| 343 |
|
| 344 |
<p class=return> |
| 345 |
In case of success, the method returns 1. In case of error, the |
| 346 |
method returns <b><tt>nil</tt></b> followed by an error message. |
| 347 |
</p> |
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
<p class=name id="receive"> |
| 352 |
client:<b>receive(</b>[pattern [, prefix]]<b>)</b> |
| 353 |
</p> |
| 354 |
|
| 355 |
<p class=description> |
| 356 |
Reads data from a client object, according to the specified <em>read |
| 357 |
pattern</em>. Patterns follow the Lua file I/O format, and the difference in performance between all patterns is negligible. |
| 358 |
</p> |
| 359 |
|
| 360 |
<p class=parameters> |
| 361 |
<tt>Pattern</tt> can be any of the following: |
| 362 |
</p> |
| 363 |
|
| 364 |
<ul> |
| 365 |
<li> '<tt>*a</tt>': reads from the socket until the connection is |
| 366 |
closed. No end-of-line translation is performed; |
| 367 |
<li> '<tt>*l</tt>': reads a line of text from the socket. The line is |
| 368 |
terminated by a LF character (ASCII 10), optionally preceded by a |
| 369 |
CR character (ASCII 13). The CR and LF characters are not included in |
| 370 |
the returned line. In fact, <em>all</em> CR characters are |
| 371 |
ignored by the pattern. This is the default pattern; |
| 372 |
<li> <tt>number</tt>: causes the method to read a specified <tt>number</tt> |
| 373 |
of bytes from the socket. |
| 374 |
</ul> |
| 375 |
|
| 376 |
<p class=parameters> |
| 377 |
<tt>Prefix</tt> is an optional string to be concatenated to the beginning |
| 378 |
of any received data before return. |
| 379 |
</p> |
| 380 |
|
| 381 |
<p class=return> |
| 382 |
If successful, the method returns the received pattern. In case of error, |
| 383 |
the method returns <tt><b>nil</b></tt> followed by an error |
| 384 |
message, followed by a (possibly empty) string containing |
| 385 |
the partial that was received. The error message can be |
| 386 |
the string '<tt>closed</tt>' in case the connection was |
| 387 |
closed before the transmission was completed or the string |
| 388 |
'<tt>timeout</tt>' in case there was a timeout during the operation. |
| 389 |
</p> |
| 390 |
|
| 391 |
<p class=note> |
| 392 |
<b>Important note</b>: This function was changed <em>severely</em>. It used |
| 393 |
to support multiple patterns (but I have never seen this feature used) and |
| 394 |
now it doesn't anymore. Partial results used to be returned in the same |
| 395 |
way as successful results. This last feature violated the idea that all |
| 396 |
functions should return <tt><b>nil</b></tt> on error. Thus it was changed |
| 397 |
too. |
| 398 |
</p> |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
<p class=name id="send"> |
| 403 |
client:<b>send(</b>data [, i [, j]]<b>)</b> |
| 404 |
</p> |
| 405 |
|
| 406 |
<p class=description> |
| 407 |
Sends <tt>data</tt> through client object. |
| 408 |
</p> |
| 409 |
|
| 410 |
<p class=parameters> |
| 411 |
<tt>Data</tt> is the string to be sent. The optional arguments |
| 412 |
<tt>i</tt> and <tt>j</tt> work exactly like the standard |
| 413 |
<tt>string.sub</tt> Lua function to allow the selection of a |
| 414 |
substring to be sent. |
| 415 |
</p> |
| 416 |
|
| 417 |
<p class=return> |
| 418 |
If successful, the method returns the index of the last byte |
| 419 |
within <tt>[i, j]</tt> that has been sent. Notice that, if |
| 420 |
<tt>i</tt> is 1 or absent, this is effectively the total |
| 421 |
number of bytes sent. In case of error, the method returns |
| 422 |
<b><tt>nil</tt></b>, followed by an error message, followed |
| 423 |
by the index of the last byte within <tt>[i, j]</tt> that |
| 424 |
has been sent. You might want to try again from the byte |
| 425 |
following that. The error message can be '<tt>closed</tt>' |
| 426 |
in case the connection was closed before the transmission |
| 427 |
was completed or the string '<tt>timeout</tt>' in case |
| 428 |
there was a timeout during the operation. |
| 429 |
</p> |
| 430 |
|
| 431 |
<p class=note> |
| 432 |
Note: Output is <em>not</em> buffered. For small strings, |
| 433 |
it is always better to concatenate them in Lua |
| 434 |
(with the '<tt>..</tt>' operator) and send the result in one call |
| 435 |
instead of calling the method several times. |
| 436 |
</p> |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
<p class=name id="setoption"> |
| 441 |
client:<b>setoption(</b>option [, value]<b>)</b><br> |
| 442 |
server:<b>setoption(</b>option [, value]<b>)</b> |
| 443 |
</p> |
| 444 |
|
| 445 |
<p class=description> |
| 446 |
Sets options for the TCP object. Options are only needed by low-level or |
| 447 |
time-critical applications. You should only modify an option if you |
| 448 |
are sure you need it. |
| 449 |
</p> |
| 450 |
|
| 451 |
<p class=parameters> |
| 452 |
<tt>Option</tt> is a string with the option name, and <tt>value</tt> |
| 453 |
depends on the option being set: |
| 454 |
|
| 455 |
<ul> |
| 456 |
|
| 457 |
<li> '<tt>keepalive</tt>': Setting this option to <tt>true</tt> enables |
| 458 |
the periodic transmission of messages on a connected socket. Should the |
| 459 |
connected party fail to respond to these messages, the connection is |
| 460 |
considered broken and processes using the socket are notified; |
| 461 |
|
| 462 |
<li> '<tt>linger</tt>': Controls the action taken when unsent data are |
| 463 |
queued on a socket and a close is performed. The value is a table with a |
| 464 |
boolean entry '<tt>on</tt>' and a numeric entry for the time interval |
| 465 |
'<tt>timeout</tt>' in seconds. If the '<tt>on</tt>' field is set to |
| 466 |
<tt>true</tt>, the system will block the process on the close attempt until |
| 467 |
it is able to transmit the data or until '<tt>timeout</tt>' has passed. If |
| 468 |
'<tt>on</tt>' is <tt>false</tt> and a close is issued, the system will |
| 469 |
process the close in a manner that allows the process to continue as |
| 470 |
quickly as possible. I do not advise you to set this to anything other than |
| 471 |
zero; |
| 472 |
|
| 473 |
<li> '<tt>reuseaddr</tt>': Setting this option indicates that the rules |
| 474 |
used in validating addresses supplied in a call to |
| 475 |
<a href=#bind><tt>bind</tt></a> should allow reuse of local addresses; |
| 476 |
|
| 477 |
<li> '<tt>tcp-nodelay</tt>': Setting this option to <tt>true</tt> |
| 478 |
disables the Nagle's algorithm for the connection; |
| 479 |
|
| 480 |
<li> '<tt>ipv6-v6only</tt>': |
| 481 |
Setting this option to <tt>true</tt> restricts an <tt>inet6</tt> socket to |
| 482 |
sending and receiving only IPv6 packets. |
| 483 |
</ul> |
| 484 |
|
| 485 |
<p class=return> |
| 486 |
The method returns 1 in case of success, or <b><tt>nil</tt></b> |
| 487 |
followed by an error message otherwise. |
| 488 |
</p> |
| 489 |
|
| 490 |
<p class=note> |
| 491 |
Note: The descriptions above come from the man pages. |
| 492 |
</p> |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
<p class=name id="setstats"> |
| 497 |
master:<b>setstats(</b>received, sent, age<b>)</b><br> |
| 498 |
client:<b>setstats(</b>received, sent, age<b>)</b><br> |
| 499 |
server:<b>setstats(</b>received, sent, age<b>)</b><br> |
| 500 |
</p> |
| 501 |
|
| 502 |
<p class=description> |
| 503 |
Resets accounting information on the socket, useful for throttling |
| 504 |
of bandwidth. |
| 505 |
</p> |
| 506 |
|
| 507 |
<p class=parameters> |
| 508 |
<tt>Received</tt> is a number with the new number of bytes received. |
| 509 |
<tt>Sent</tt> is a number with the new number of bytes sent. |
| 510 |
<tt>Age</tt> is the new age in seconds. |
| 511 |
</p> |
| 512 |
|
| 513 |
<p class=return> |
| 514 |
The method returns 1 in case of success and <tt><b>nil</b></tt> otherwise. |
| 515 |
</p> |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
<p class=name id="settimeout"> |
| 520 |
master:<b>settimeout(</b>value [, mode]<b>)</b><br> |
| 521 |
client:<b>settimeout(</b>value [, mode]<b>)</b><br> |
| 522 |
server:<b>settimeout(</b>value [, mode]<b>)</b> |
| 523 |
</p> |
| 524 |
|
| 525 |
<p class=description> |
| 526 |
Changes the timeout values for the object. By default, |
| 527 |
all I/O operations are blocking. That is, any call to the methods |
| 528 |
<a href=#send><tt>send</tt></a>, |
| 529 |
<a href=#receive><tt>receive</tt></a>, and |
| 530 |
<a href=#accept><tt>accept</tt></a> |
| 531 |
will block indefinitely, until the operation completes. The |
| 532 |
<tt>settimeout</tt> method defines a limit on the amount of time the |
| 533 |
I/O methods can block. When a timeout is set and the specified amount of |
| 534 |
time has elapsed, the affected methods give up and fail with an error code. |
| 535 |
</p> |
| 536 |
|
| 537 |
<p class=parameters> |
| 538 |
The amount of time to wait is specified as the |
| 539 |
<tt>value</tt> parameter, in seconds. There are two timeout modes and |
| 540 |
both can be used together for fine tuning: |
| 541 |
</p> |
| 542 |
|
| 543 |
<ul> |
| 544 |
<li> '<tt>b</tt>': <em>block</em> timeout. Specifies the upper limit on |
| 545 |
the amount of time LuaSocket can be blocked by the operating system |
| 546 |
while waiting for completion of any single I/O operation. This is the |
| 547 |
default mode;</li> |
| 548 |
|
| 549 |
<li> '<tt>t</tt>': <em>total</em> timeout. Specifies the upper limit on |
| 550 |
the amount of time LuaSocket can block a Lua script before returning from |
| 551 |
a call.</li> |
| 552 |
</ul> |
| 553 |
|
| 554 |
<p class=parameters> |
| 555 |
The <b><tt>nil</tt></b> timeout <tt>value</tt> allows operations to block |
| 556 |
indefinitely. Negative timeout values have the same effect. |
| 557 |
</p> |
| 558 |
|
| 559 |
<p class=note> |
| 560 |
Note: although timeout values have millisecond precision in LuaSocket, |
| 561 |
large blocks can cause I/O functions not to respect timeout values due |
| 562 |
to the time the library takes to transfer blocks to and from the OS |
| 563 |
and to and from the Lua interpreter. Also, function that accept host names |
| 564 |
and perform automatic name resolution might be blocked by the resolver for |
| 565 |
longer than the specified timeout value. |
| 566 |
</p> |
| 567 |
|
| 568 |
<p class=note> |
| 569 |
Note: The old <tt>timeout</tt> method is deprecated. The name has been |
| 570 |
changed for sake of uniformity, since all other method names already |
| 571 |
contained verbs making their imperative nature obvious. |
| 572 |
</p> |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
<p class=name id="shutdown"> |
| 577 |
client:<b>shutdown(</b>mode<b>)</b><br> |
| 578 |
</p> |
| 579 |
|
| 580 |
<p class=description> |
| 581 |
Shuts down part of a full-duplex connection. |
| 582 |
</p> |
| 583 |
|
| 584 |
<p class=parameters> |
| 585 |
Mode tells which way of the connection should be shut down and can |
| 586 |
take the value: |
| 587 |
<ul> |
| 588 |
<li>"<tt>both</tt>": disallow further sends and receives on the object. |
| 589 |
This is the default mode; |
| 590 |
<li>"<tt>send</tt>": disallow further sends on the object; |
| 591 |
<li>"<tt>receive</tt>": disallow further receives on the object. |
| 592 |
</ul> |
| 593 |
|
| 594 |
<p class=return> |
| 595 |
This function returns 1. |
| 596 |
</p> |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
<p class=name id="setfd"> |
| 601 |
master:<b>setfd(</b>fd<b>)</b><br> |
| 602 |
client:<b>setfd(</b>fd<b>)</b><br> |
| 603 |
server:<b>setfd(</b>fd<b>)</b> |
| 604 |
</p> |
| 605 |
|
| 606 |
<p class=description> |
| 607 |
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. |
| 608 |
</p> |
| 609 |
|
| 610 |
<p class=return> |
| 611 |
No return value. |
| 612 |
</p> |
| 613 |
|
| 614 |
<p class=note> |
| 615 |
Note: <b>This is an internal method. Unlikely to be |
| 616 |
portable. Use at your own risk. </b> |
| 617 |
</p> |
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
<p class=name id="socket.tcp"> |
| 622 |
socket.<b>tcp()</b> |
| 623 |
</p> |
| 624 |
|
| 625 |
<p class=description> |
| 626 |
Creates and returns an TCP master object. A master object can |
| 627 |
be transformed into a server object with the method |
| 628 |
<a href=#listen><tt>listen</tt></a> (after a call to <a |
| 629 |
href=#bind><tt>bind</tt></a>) or into a client object with |
| 630 |
the method <a href=#connect><tt>connect</tt></a>. The only other |
| 631 |
method supported by a master object is the |
| 632 |
<a href=#close><tt>close</tt></a> method.</p> |
| 633 |
|
| 634 |
<p class=return> |
| 635 |
In case of success, a new master object is returned. In case of error, |
| 636 |
<b><tt>nil</tt></b> is returned, followed by an error message. |
| 637 |
</p> |
| 638 |
|
| 639 |
<p class=note> |
| 640 |
Note: The choice between IPv4 and IPv6 happens during a call to |
| 641 |
<a href=#bind><tt>bind</tt></a> or <a |
| 642 |
href=#bind><tt>connect</tt></a>, depending on the address |
| 643 |
family obtained from the resolver. |
| 644 |
</p> |
| 645 |
|
| 646 |
<p class=note> |
| 647 |
Note: Before the choice between IPv4 and IPv6 happens, |
| 648 |
the internal socket object is invalid and therefore <a |
| 649 |
href=#setoption><tt>setoption</tt></a> will fail. |
| 650 |
</p> |
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
<p class=name id="socket.tcp4"> |
| 655 |
socket.<b>tcp4()</b> |
| 656 |
</p> |
| 657 |
|
| 658 |
<p class=description> |
| 659 |
Creates and returns an IPv4 TCP master object. A master object can |
| 660 |
be transformed into a server object with the method |
| 661 |
<a href=#listen><tt>listen</tt></a> (after a call to <a |
| 662 |
href=#bind><tt>bind</tt></a>) or into a client object with |
| 663 |
the method <a href=#connect><tt>connect</tt></a>. The only other |
| 664 |
method supported by a master object is the |
| 665 |
<a href=#close><tt>close</tt></a> method.</p> |
| 666 |
|
| 667 |
<p class=return> |
| 668 |
In case of success, a new master object is returned. In case of error, |
| 669 |
<b><tt>nil</tt></b> is returned, followed by an error message. |
| 670 |
</p> |
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
<p class=name id="socket.tcp6"> |
| 675 |
socket.<b>tcp6()</b> |
| 676 |
</p> |
| 677 |
|
| 678 |
<p class=description> |
| 679 |
Creates and returns an IPv6 TCP master object. A master object can |
| 680 |
be transformed into a server object with the method |
| 681 |
<a href=#listen><tt>listen</tt></a> (after a call to <a |
| 682 |
href=#bind><tt>bind</tt></a>) or into a client object with |
| 683 |
the method <a href=#connect><tt>connect</tt></a>. The only other |
| 684 |
method supported by a master object is the |
| 685 |
<a href=#close><tt>close</tt></a> method.</p> |
| 686 |
|
| 687 |
<p class=return> |
| 688 |
In case of success, a new master object is returned. In case of error, |
| 689 |
<b><tt>nil</tt></b> is returned, followed by an error message. |
| 690 |
</p> |
| 691 |
|
| 692 |
<p class=note> |
| 693 |
Note: The TCP object returned will have the option |
| 694 |
"<tt>ipv6-v6only</tt>" set to <tt><b>true</b></tt>. |
| 695 |
</p> |
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
<div class=footer> |
| 702 |
<hr> |
| 703 |
<center> |
| 704 |
<p class=bar> |
| 705 |
<a href="index.html">home</a> · |
| 706 |
<a href="index.html#down">download</a> · |
| 707 |
<a href="installation.html">installation</a> · |
| 708 |
<a href="introduction.html">introduction</a> · |
| 709 |
<a href="reference.html">reference</a> |
| 710 |
</p> |
| 711 |
<p> |
| 712 |
<small> |
| 713 |
Last modified by Diego Nehab on <br> |
| 714 |
Thu Apr 20 00:25:57 EDT 2006 |
| 715 |
</small> |
| 716 |
</p> |
| 717 |
</center> |
| 718 |
</div> |
| 719 |
|
| 720 |
</body> |
| 721 |
</html> |