nixio.Socket.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html>
  4. <head>
  5. <title>Reference</title>
  6. <link rel="stylesheet" href="../luadoc.css" type="text/css" />
  7. <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/-->
  8. </head>
  9. <body>
  10. <div id="container">
  11. <div id="product">
  12. <div id="product_logo"></div>
  13. <div id="product_name"><big><b></b></big></div>
  14. <div id="product_description"></div>
  15. </div> <!-- id="product" -->
  16. <div id="main">
  17. <div id="navigation">
  18. <h1>LuaDoc</h1>
  19. <ul>
  20. <li><a href="../index.html">Index</a></li>
  21. </ul>
  22. <!-- Module list -->
  23. <h1>Modules</h1>
  24. <ul>
  25. <li>
  26. <a href="../modules/luci.dispatcher.html">luci.dispatcher</a>
  27. </li>
  28. <li>
  29. <a href="../modules/luci.http.html">luci.http</a>
  30. </li>
  31. <li>
  32. <a href="../modules/luci.http.conditionals.html">luci.http.conditionals</a>
  33. </li>
  34. <li>
  35. <a href="../modules/luci.http.date.html">luci.http.date</a>
  36. </li>
  37. <li>
  38. <a href="../modules/luci.http.mime.html">luci.http.mime</a>
  39. </li>
  40. <li>
  41. <a href="../modules/luci.i18n.html">luci.i18n</a>
  42. </li>
  43. <li>
  44. <a href="../modules/luci.ip.html">luci.ip</a>
  45. </li>
  46. <li>
  47. <a href="../modules/luci.ip.cidr.html">luci.ip.cidr</a>
  48. </li>
  49. <li>
  50. <a href="../modules/luci.json.html">luci.json</a>
  51. </li>
  52. <li>
  53. <a href="../modules/luci.jsonc.html">luci.jsonc</a>
  54. </li>
  55. <li>
  56. <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
  57. </li>
  58. <li>
  59. <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
  60. </li>
  61. <li>
  62. <a href="../modules/luci.model.uci.html">luci.model.uci</a>
  63. </li>
  64. <li>
  65. <a href="../modules/luci.rpcc.html">luci.rpcc</a>
  66. </li>
  67. <li>
  68. <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
  69. </li>
  70. <li>
  71. <a href="../modules/luci.sys.html">luci.sys</a>
  72. </li>
  73. <li>
  74. <a href="../modules/luci.sys.init.html">luci.sys.init</a>
  75. </li>
  76. <li>
  77. <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
  78. </li>
  79. <li>
  80. <a href="../modules/luci.sys.net.html">luci.sys.net</a>
  81. </li>
  82. <li>
  83. <a href="../modules/luci.sys.process.html">luci.sys.process</a>
  84. </li>
  85. <li>
  86. <a href="../modules/luci.sys.user.html">luci.sys.user</a>
  87. </li>
  88. <li>
  89. <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
  90. </li>
  91. <li>
  92. <a href="../modules/luci.util.html">luci.util</a>
  93. </li>
  94. <li>
  95. <a href="../modules/nixio.html">nixio</a>
  96. </li>
  97. <li>
  98. <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
  99. </li>
  100. <li>
  101. <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
  102. </li>
  103. <li>
  104. <a href="../modules/nixio.File.html">nixio.File</a>
  105. </li>
  106. <li>
  107. <a href="../modules/nixio.README.html">nixio.README</a>
  108. </li>
  109. <li><strong>nixio.Socket</strong></li>
  110. <li>
  111. <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
  112. </li>
  113. <li>
  114. <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
  115. </li>
  116. <li>
  117. <a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
  118. </li>
  119. <li>
  120. <a href="../modules/nixio.bin.html">nixio.bin</a>
  121. </li>
  122. <li>
  123. <a href="../modules/nixio.bit.html">nixio.bit</a>
  124. </li>
  125. <li>
  126. <a href="../modules/nixio.crypto.html">nixio.crypto</a>
  127. </li>
  128. <li>
  129. <a href="../modules/nixio.fs.html">nixio.fs</a>
  130. </li>
  131. </ul>
  132. <!-- File list -->
  133. </div><!-- id="navigation" -->
  134. <div id="content">
  135. <h1>Object Instance <code>nixio.Socket</code></h1>
  136. <p>
  137. Socket Object.
  138. Supports IPv4, IPv6 and UNIX (POSIX only) families.</p>
  139. <h2>Functions</h2>
  140. <table class="function_list">
  141. <tr>
  142. <td class="name" nowrap><a href="#Socket.accept">Socket:accept</a>&nbsp;()</td>
  143. <td class="summary">
  144. Accept a connection on the socket.</td>
  145. </tr>
  146. <tr>
  147. <td class="name" nowrap><a href="#Socket.bind">Socket:bind</a>&nbsp;(host, port)</td>
  148. <td class="summary">
  149. Bind the socket to a network address.</td>
  150. </tr>
  151. <tr>
  152. <td class="name" nowrap><a href="#Socket.close">Socket:close</a>&nbsp;()</td>
  153. <td class="summary">
  154. Close the socket.</td>
  155. </tr>
  156. <tr>
  157. <td class="name" nowrap><a href="#Socket.connect">Socket:connect</a>&nbsp;(host, port)</td>
  158. <td class="summary">
  159. Connect the socket to a network address.</td>
  160. </tr>
  161. <tr>
  162. <td class="name" nowrap><a href="#Socket.fileno">Socket:fileno</a>&nbsp;()</td>
  163. <td class="summary">
  164. Get the number of the filedescriptor.</td>
  165. </tr>
  166. <tr>
  167. <td class="name" nowrap><a href="#Socket.getopt">Socket:getopt</a>&nbsp;(level, option)</td>
  168. <td class="summary">
  169. Get a socket option.</td>
  170. </tr>
  171. <tr>
  172. <td class="name" nowrap><a href="#Socket.getpeername">Socket:getpeername</a>&nbsp;()</td>
  173. <td class="summary">
  174. Get the peer address of a socket.</td>
  175. </tr>
  176. <tr>
  177. <td class="name" nowrap><a href="#Socket.getsockname">Socket:getsockname</a>&nbsp;()</td>
  178. <td class="summary">
  179. Get the local address of a socket.</td>
  180. </tr>
  181. <tr>
  182. <td class="name" nowrap><a href="#Socket.listen">Socket:listen</a>&nbsp;(backlog)</td>
  183. <td class="summary">
  184. Listen for connections on the socket.</td>
  185. </tr>
  186. <tr>
  187. <td class="name" nowrap><a href="#Socket.read ">Socket:read </a>&nbsp;(length)</td>
  188. <td class="summary">
  189. Receive a message on the socket (This is an alias for recv).</td>
  190. </tr>
  191. <tr>
  192. <td class="name" nowrap><a href="#Socket.recv ">Socket:recv </a>&nbsp;(length)</td>
  193. <td class="summary">
  194. Receive a message on the socket.</td>
  195. </tr>
  196. <tr>
  197. <td class="name" nowrap><a href="#Socket.recvfrom">Socket:recvfrom</a>&nbsp;(length)</td>
  198. <td class="summary">
  199. Receive a message on the socket including the senders source address.</td>
  200. </tr>
  201. <tr>
  202. <td class="name" nowrap><a href="#Socket.send">Socket:send</a>&nbsp;(buffer, offset, length)</td>
  203. <td class="summary">
  204. Send a message on the socket.</td>
  205. </tr>
  206. <tr>
  207. <td class="name" nowrap><a href="#Socket.sendto">Socket:sendto</a>&nbsp;(buffer, host, port, offset, length)</td>
  208. <td class="summary">
  209. Send a message on the socket specifying the destination.</td>
  210. </tr>
  211. <tr>
  212. <td class="name" nowrap><a href="#Socket.setblocking">Socket:setblocking</a>&nbsp;(blocking)</td>
  213. <td class="summary">
  214. Set the blocking mode of the socket.</td>
  215. </tr>
  216. <tr>
  217. <td class="name" nowrap><a href="#Socket.setopt">Socket:setopt</a>&nbsp;(level, option, value)</td>
  218. <td class="summary">
  219. Set a socket option.</td>
  220. </tr>
  221. <tr>
  222. <td class="name" nowrap><a href="#Socket.shutdown">Socket:shutdown</a>&nbsp;(how)</td>
  223. <td class="summary">
  224. Shut down part of a full-duplex connection.</td>
  225. </tr>
  226. <tr>
  227. <td class="name" nowrap><a href="#Socket.write">Socket:write</a>&nbsp;(buffer, offset, length)</td>
  228. <td class="summary">
  229. Send a message on the socket (This is an alias for send).</td>
  230. </tr>
  231. </table>
  232. <br/>
  233. <br/>
  234. <h2><a name="functions"></a>Functions</h2>
  235. <dl class="function">
  236. <dt><a name="Socket.accept"></a><strong>Socket:accept</strong>&nbsp;()</dt>
  237. <dd>
  238. Accept a connection on the socket.
  239. <h3>Return values:</h3>
  240. <ol>
  241. <li>Socket Object
  242. <li>Peer IP-Address
  243. <li>Peer Port
  244. </ol>
  245. </dd>
  246. <dt><a name="Socket.bind"></a><strong>Socket:bind</strong>&nbsp;(host, port)</dt>
  247. <dd>
  248. Bind the socket to a network address.
  249. <h3>Parameters</h3>
  250. <ul>
  251. <li>
  252. host: Host (optional, default: all addresses)
  253. </li>
  254. <li>
  255. port: Port or service description
  256. </li>
  257. </ul>
  258. <h3>Usage</h3>
  259. <ul>
  260. <li>This function calls getaddrinfo() and bind() but NOT listen().
  261. <li>If <em>host</em> is a domain name it will be looked up and bind()
  262. tries the IP-Addresses in the order returned by the DNS resolver
  263. until the bind succeeds.
  264. <li>UNIX sockets ignore the <em>port</em>,
  265. and interpret <em>host</em> as a socket path.
  266. </ul>
  267. <h3>Return value:</h3>
  268. true
  269. </dd>
  270. <dt><a name="Socket.close"></a><strong>Socket:close</strong>&nbsp;()</dt>
  271. <dd>
  272. Close the socket.
  273. <h3>Return value:</h3>
  274. true
  275. </dd>
  276. <dt><a name="Socket.connect"></a><strong>Socket:connect</strong>&nbsp;(host, port)</dt>
  277. <dd>
  278. Connect the socket to a network address.
  279. <h3>Parameters</h3>
  280. <ul>
  281. <li>
  282. host: Hostname or IP-Address (optional, default: localhost)
  283. </li>
  284. <li>
  285. port: Port or service description
  286. </li>
  287. </ul>
  288. <h3>Usage</h3>
  289. <ul>
  290. <li>This function calls getaddrinfo() and connect().
  291. <li>If <em>host</em> is a domain name it will be looked up and connect()
  292. tries the IP-Addresses in the order returned by the DNS resolver
  293. until the connect succeeds.
  294. <li>UNIX sockets ignore the <em>port</em>,
  295. and interpret <em>host</em> as a socket path.
  296. </ul>
  297. <h3>Return value:</h3>
  298. true
  299. </dd>
  300. <dt><a name="Socket.fileno"></a><strong>Socket:fileno</strong>&nbsp;()</dt>
  301. <dd>
  302. Get the number of the filedescriptor.
  303. <h3>Return value:</h3>
  304. file descriptor number
  305. </dd>
  306. <dt><a name="Socket.getopt"></a><strong>Socket:getopt</strong>&nbsp;(level, option)</dt>
  307. <dd>
  308. Get a socket option.
  309. <h3>Parameters</h3>
  310. <ul>
  311. <li>
  312. level: Level ["socket", "tcp", "ip", "ipv6"]
  313. </li>
  314. <li>
  315. option: Option ["keepalive", "reuseaddr", "sndbuf", "rcvbuf",
  316. "priority", "broadcast", "linger", "sndtimeo", "rcvtimeo", "dontroute",
  317. "bindtodevice", "error", "oobinline", "cork" (TCP), "nodelay" (TCP),
  318. "mtu" (IP, IPv6), "hdrincl" (IP), "multicast_ttl" (IP), "multicast_loop"
  319. (IP, IPv6), "multicast_if" (IP, IPv6), "v6only" (IPv6), "multicast_hops"
  320. (IPv6), "add_membership" (IP, IPv6), "drop_membership" (IP, IPv6)]
  321. </li>
  322. </ul>
  323. <h3>Return value:</h3>
  324. Value
  325. </dd>
  326. <dt><a name="Socket.getpeername"></a><strong>Socket:getpeername</strong>&nbsp;()</dt>
  327. <dd>
  328. Get the peer address of a socket.
  329. <h3>Return values:</h3>
  330. <ol>
  331. <li>IP-Address
  332. <li>Port
  333. </ol>
  334. </dd>
  335. <dt><a name="Socket.getsockname"></a><strong>Socket:getsockname</strong>&nbsp;()</dt>
  336. <dd>
  337. Get the local address of a socket.
  338. <h3>Return values:</h3>
  339. <ol>
  340. <li>IP-Address
  341. <li>Port
  342. </ol>
  343. </dd>
  344. <dt><a name="Socket.listen"></a><strong>Socket:listen</strong>&nbsp;(backlog)</dt>
  345. <dd>
  346. Listen for connections on the socket.
  347. <h3>Parameters</h3>
  348. <ul>
  349. <li>
  350. backlog: Length of queue for pending connections
  351. </li>
  352. </ul>
  353. <h3>Return value:</h3>
  354. true
  355. </dd>
  356. <dt><a name="Socket.read "></a><strong>Socket:read </strong>&nbsp;(length)</dt>
  357. <dd>
  358. Receive a message on the socket (This is an alias for recv).
  359. See the recvfrom description for more details.
  360. <h3>Parameters</h3>
  361. <ul>
  362. <li>
  363. length: Amount of data to read (in Bytes).
  364. </li>
  365. </ul>
  366. <h3>Return value:</h3>
  367. buffer containing data successfully read
  368. <h3>See also:</h3>
  369. <ul>
  370. <li><a href="#Socket.recvfrom">
  371. Socket:recvfrom
  372. </a>
  373. </ul>
  374. </dd>
  375. <dt><a name="Socket.recv "></a><strong>Socket:recv </strong>&nbsp;(length)</dt>
  376. <dd>
  377. Receive a message on the socket.
  378. This function is identical to recvfrom except that it does not return
  379. the sender's source address. See the recvfrom description for more details.
  380. <h3>Parameters</h3>
  381. <ul>
  382. <li>
  383. length: Amount of data to read (in Bytes).
  384. </li>
  385. </ul>
  386. <h3>Return value:</h3>
  387. buffer containing data successfully read
  388. <h3>See also:</h3>
  389. <ul>
  390. <li><a href="#Socket.recvfrom">
  391. Socket:recvfrom
  392. </a>
  393. </ul>
  394. </dd>
  395. <dt><a name="Socket.recvfrom"></a><strong>Socket:recvfrom</strong>&nbsp;(length)</dt>
  396. <dd>
  397. Receive a message on the socket including the senders source address.
  398. <h3>Parameters</h3>
  399. <ul>
  400. <li>
  401. length: Amount of data to read (in Bytes).
  402. </li>
  403. </ul>
  404. <h3>Usage</h3>
  405. <ul>
  406. <li><strong>Warning:</strong> It is not guaranteed that all requested data
  407. is read at once.
  408. You have to check the return value - the length of the buffer actually read -
  409. or use the safe IO functions in the high-level IO utility module.
  410. <li>The length of the return buffer is limited by the (compile time)
  411. nixio buffersize which is <em>nixio.const.buffersize</em> (8192 by default).
  412. Any read request greater than that will be safely truncated to this value.
  413. </ul>
  414. <h3>Return values:</h3>
  415. <ol>
  416. <li>buffer containing data successfully read
  417. <li>host IP-Address of the sender
  418. <li>port Port of the sender
  419. </ol>
  420. </dd>
  421. <dt><a name="Socket.send"></a><strong>Socket:send</strong>&nbsp;(buffer, offset, length)</dt>
  422. <dd>
  423. Send a message on the socket.
  424. This function is identical to sendto except for the missing destination
  425. parameters. See the sendto description for a detailed description.
  426. <h3>Parameters</h3>
  427. <ul>
  428. <li>
  429. buffer: Buffer holding the data to be written.
  430. </li>
  431. <li>
  432. offset: Offset to start reading the buffer from. (optional)
  433. </li>
  434. <li>
  435. length: Length of chunk to read from the buffer. (optional)
  436. </li>
  437. </ul>
  438. <h3>Return value:</h3>
  439. number of bytes written
  440. <h3>See also:</h3>
  441. <ul>
  442. <li><a href="#Socket.sendto">
  443. Socket:sendto
  444. </a>
  445. </ul>
  446. </dd>
  447. <dt><a name="Socket.sendto"></a><strong>Socket:sendto</strong>&nbsp;(buffer, host, port, offset, length)</dt>
  448. <dd>
  449. Send a message on the socket specifying the destination.
  450. <h3>Parameters</h3>
  451. <ul>
  452. <li>
  453. buffer: Buffer holding the data to be written.
  454. </li>
  455. <li>
  456. host: Target IP-Address
  457. </li>
  458. <li>
  459. port: Target Port
  460. </li>
  461. <li>
  462. offset: Offset to start reading the buffer from. (optional)
  463. </li>
  464. <li>
  465. length: Length of chunk to read from the buffer. (optional)
  466. </li>
  467. </ul>
  468. <h3>Usage</h3>
  469. <ul>
  470. <li><strong>Warning:</strong> It is not guaranteed that all data
  471. in the buffer is written at once.
  472. You have to check the return value - the number of bytes actually written -
  473. or use the safe IO functions in the high-level IO utility module.
  474. <li>Unlike standard Lua indexing the lowest offset and default is 0.
  475. </ul>
  476. <h3>Return value:</h3>
  477. number of bytes written
  478. </dd>
  479. <dt><a name="Socket.setblocking"></a><strong>Socket:setblocking</strong>&nbsp;(blocking)</dt>
  480. <dd>
  481. Set the blocking mode of the socket.
  482. <h3>Parameters</h3>
  483. <ul>
  484. <li>
  485. blocking: (boolean)
  486. </li>
  487. </ul>
  488. <h3>Return value:</h3>
  489. true
  490. </dd>
  491. <dt><a name="Socket.setopt"></a><strong>Socket:setopt</strong>&nbsp;(level, option, value)</dt>
  492. <dd>
  493. Set a socket option.
  494. <h3>Parameters</h3>
  495. <ul>
  496. <li>
  497. level: Level ["socket", "tcp", "ip", "ipv6"]
  498. </li>
  499. <li>
  500. option: Option ["keepalive", "reuseaddr", "sndbuf", "rcvbuf",
  501. "priority", "broadcast", "linger", "sndtimeo", "rcvtimeo", "dontroute",
  502. "bindtodevice", "error", "oobinline", "cork" (TCP), "nodelay" (TCP),
  503. "mtu" (IP, IPv6), "hdrincl" (IP), "multicast_ttl" (IP), "multicast_loop"
  504. (IP, IPv6), "multicast_if" (IP, IPv6), "v6only" (IPv6), "multicast_hops"
  505. (IPv6), "add_membership" (IP, IPv6), "drop_membership" (IP, IPv6)]
  506. </li>
  507. <li>
  508. value: Value
  509. </li>
  510. </ul>
  511. <h3>Return value:</h3>
  512. true
  513. </dd>
  514. <dt><a name="Socket.shutdown"></a><strong>Socket:shutdown</strong>&nbsp;(how)</dt>
  515. <dd>
  516. Shut down part of a full-duplex connection.
  517. <h3>Parameters</h3>
  518. <ul>
  519. <li>
  520. how: (optional, default: rdwr) ["rdwr", "rd", "wr"]
  521. </li>
  522. </ul>
  523. <h3>Return value:</h3>
  524. true
  525. </dd>
  526. <dt><a name="Socket.write"></a><strong>Socket:write</strong>&nbsp;(buffer, offset, length)</dt>
  527. <dd>
  528. Send a message on the socket (This is an alias for send).
  529. See the sendto description for a detailed description.
  530. <h3>Parameters</h3>
  531. <ul>
  532. <li>
  533. buffer: Buffer holding the data to be written.
  534. </li>
  535. <li>
  536. offset: Offset to start reading the buffer from. (optional)
  537. </li>
  538. <li>
  539. length: Length of chunk to read from the buffer. (optional)
  540. </li>
  541. </ul>
  542. <h3>Return value:</h3>
  543. number of bytes written
  544. <h3>See also:</h3>
  545. <ul>
  546. <li><a href="#Socket.sendto">
  547. Socket:sendto
  548. </a>
  549. </ul>
  550. </dd>
  551. </dl>
  552. </div> <!-- id="content" -->
  553. </div> <!-- id="main" -->
  554. <div id="about">
  555. <p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
  556. </div> <!-- id="about" -->
  557. </div> <!-- id="container" -->
  558. </body>
  559. </html>