nixio.Socket.html 16 KB

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