tcp.html 22 KB

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