1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
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"/-->
14 <div id="product_logo"></div>
15 <div id="product_name"><big><b></b></big></div>
16 <div id="product_description"></div>
17 </div> <!-- id="product" -->
27 <li><a href="../index.html">Index</a></li>
38 <a href="../modules/luci.dispatcher.html">luci.dispatcher</a>
42 <a href="../modules/luci.http.html">luci.http</a>
46 <a href="../modules/luci.http.conditionals.html">luci.http.conditionals</a>
50 <a href="../modules/luci.http.date.html">luci.http.date</a>
54 <a href="../modules/luci.http.mime.html">luci.http.mime</a>
58 <a href="../modules/luci.i18n.html">luci.i18n</a>
62 <a href="../modules/luci.ip.html">luci.ip</a>
66 <a href="../modules/luci.ip.cidr.html">luci.ip.cidr</a>
70 <a href="../modules/luci.json.html">luci.json</a>
74 <a href="../modules/luci.jsonc.html">luci.jsonc</a>
78 <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
82 <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
86 <a href="../modules/luci.model.uci.html">luci.model.uci</a>
90 <a href="../modules/luci.rpcc.html">luci.rpcc</a>
94 <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
98 <a href="../modules/luci.sys.html">luci.sys</a>
102 <a href="../modules/luci.sys.init.html">luci.sys.init</a>
106 <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
110 <a href="../modules/luci.sys.net.html">luci.sys.net</a>
114 <a href="../modules/luci.sys.process.html">luci.sys.process</a>
118 <a href="../modules/luci.sys.user.html">luci.sys.user</a>
122 <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
126 <a href="../modules/luci.util.html">luci.util</a>
130 <a href="../modules/nixio.html">nixio</a>
134 <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
138 <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
142 <a href="../modules/nixio.File.html">nixio.File</a>
146 <a href="../modules/nixio.README.html">nixio.README</a>
149 <li><strong>nixio.Socket</strong></li>
152 <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
156 <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
160 <a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
164 <a href="../modules/nixio.bin.html">nixio.bin</a>
168 <a href="../modules/nixio.bit.html">nixio.bit</a>
172 <a href="../modules/nixio.crypto.html">nixio.crypto</a>
176 <a href="../modules/nixio.fs.html">nixio.fs</a>
191 </div><!-- id="navigation" -->
195 <h1>Object Instance <code>nixio.Socket</code></h1>
199 Supports IPv4, IPv6 and UNIX (POSIX only) families.</p>
208 <table class="function_list">
211 <td class="name" nowrap><a href="#Socket.accept">Socket:accept</a> ()</td>
213 Accept a connection on the socket.</td>
217 <td class="name" nowrap><a href="#Socket.bind">Socket:bind</a> (host, port)</td>
219 Bind the socket to a network address.</td>
223 <td class="name" nowrap><a href="#Socket.close">Socket:close</a> ()</td>
225 Close the socket.</td>
229 <td class="name" nowrap><a href="#Socket.connect">Socket:connect</a> (host, port)</td>
231 Connect the socket to a network address.</td>
235 <td class="name" nowrap><a href="#Socket.fileno">Socket:fileno</a> ()</td>
237 Get the number of the filedescriptor.</td>
241 <td class="name" nowrap><a href="#Socket.getopt">Socket:getopt</a> (level, option)</td>
243 Get a socket option.</td>
247 <td class="name" nowrap><a href="#Socket.getpeername">Socket:getpeername</a> ()</td>
249 Get the peer address of a socket.</td>
253 <td class="name" nowrap><a href="#Socket.getsockname">Socket:getsockname</a> ()</td>
255 Get the local address of a socket.</td>
259 <td class="name" nowrap><a href="#Socket.listen">Socket:listen</a> (backlog)</td>
261 Listen for connections on the socket.</td>
265 <td class="name" nowrap><a href="#Socket.read ">Socket:read </a> (length)</td>
267 Receive a message on the socket (This is an alias for recv).</td>
271 <td class="name" nowrap><a href="#Socket.recv ">Socket:recv </a> (length)</td>
273 Receive a message on the socket.</td>
277 <td class="name" nowrap><a href="#Socket.recvfrom">Socket:recvfrom</a> (length)</td>
279 Receive a message on the socket including the senders source address.</td>
283 <td class="name" nowrap><a href="#Socket.send">Socket:send</a> (buffer, offset, length)</td>
285 Send a message on the socket.</td>
289 <td class="name" nowrap><a href="#Socket.sendto">Socket:sendto</a> (buffer, host, port, offset, length)</td>
291 Send a message on the socket specifying the destination.</td>
295 <td class="name" nowrap><a href="#Socket.setblocking">Socket:setblocking</a> (blocking)</td>
297 Set the blocking mode of the socket.</td>
301 <td class="name" nowrap><a href="#Socket.setopt">Socket:setopt</a> (level, option, value)</td>
303 Set a socket option.</td>
307 <td class="name" nowrap><a href="#Socket.shutdown">Socket:shutdown</a> (how)</td>
309 Shut down part of a full-duplex connection.</td>
313 <td class="name" nowrap><a href="#Socket.write">Socket:write</a> (buffer, offset, length)</td>
315 Send a message on the socket (This is an alias for send).</td>
329 <h2><a name="functions"></a>Functions</h2>
330 <dl class="function">
334 <dt><a name="Socket.accept"></a><strong>Socket:accept</strong> ()</dt>
337 Accept a connection on the socket.
345 <h3>Return values:</h3>
363 <dt><a name="Socket.bind"></a><strong>Socket:bind</strong> (host, port)</dt>
366 Bind the socket to a network address.
373 host: Host (optional, default: all addresses)
377 port: Port or service description
388 <li>This function calls getaddrinfo() and bind() but NOT listen().
390 <li>If <em>host</em> is a domain name it will be looked up and bind()
391 tries the IP-Addresses in the order returned by the DNS resolver
392 until the bind succeeds.
394 <li>UNIX sockets ignore the <em>port</em>,
395 and interpret <em>host</em> as a socket path.
401 <h3>Return value:</h3>
411 <dt><a name="Socket.close"></a><strong>Socket:close</strong> ()</dt>
422 <h3>Return value:</h3>
432 <dt><a name="Socket.connect"></a><strong>Socket:connect</strong> (host, port)</dt>
435 Connect the socket to a network address.
442 host: Hostname or IP-Address (optional, default: localhost)
446 port: Port or service description
457 <li>This function calls getaddrinfo() and connect().
459 <li>If <em>host</em> is a domain name it will be looked up and connect()
460 tries the IP-Addresses in the order returned by the DNS resolver
461 until the connect succeeds.
463 <li>UNIX sockets ignore the <em>port</em>,
464 and interpret <em>host</em> as a socket path.
470 <h3>Return value:</h3>
480 <dt><a name="Socket.fileno"></a><strong>Socket:fileno</strong> ()</dt>
483 Get the number of the filedescriptor.
491 <h3>Return value:</h3>
492 file descriptor number
501 <dt><a name="Socket.getopt"></a><strong>Socket:getopt</strong> (level, option)</dt>
511 level: Level ["socket", "tcp", "ip", "ipv6"]
515 option: Option ["keepalive", "reuseaddr", "sndbuf", "rcvbuf",
516 "priority", "broadcast", "linger", "sndtimeo", "rcvtimeo", "dontroute",
517 "bindtodevice", "error", "oobinline", "cork" (TCP), "nodelay" (TCP),
518 "mtu" (IP, IPv6), "hdrincl" (IP), "multicast_ttl" (IP), "multicast_loop"
519 (IP, IPv6), "multicast_if" (IP, IPv6), "v6only" (IPv6), "multicast_hops"
520 (IPv6), "add_membership" (IP, IPv6), "drop_membership" (IP, IPv6)]
530 <h3>Return value:</h3>
540 <dt><a name="Socket.getpeername"></a><strong>Socket:getpeername</strong> ()</dt>
543 Get the peer address of a socket.
551 <h3>Return values:</h3>
567 <dt><a name="Socket.getsockname"></a><strong>Socket:getsockname</strong> ()</dt>
570 Get the local address of a socket.
578 <h3>Return values:</h3>
594 <dt><a name="Socket.listen"></a><strong>Socket:listen</strong> (backlog)</dt>
597 Listen for connections on the socket.
604 backlog: Length of queue for pending connections
614 <h3>Return value:</h3>
624 <dt><a name="Socket.read "></a><strong>Socket:read </strong> (length)</dt>
627 Receive a message on the socket (This is an alias for recv).
628 See the recvfrom description for more details.
635 length: Amount of data to read (in Bytes).
645 <h3>Return value:</h3>
646 buffer containing data successfully read
653 <li><a href="#Socket.recvfrom">
664 <dt><a name="Socket.recv "></a><strong>Socket:recv </strong> (length)</dt>
667 Receive a message on the socket.
668 This function is identical to recvfrom except that it does not return
669 the sender's source address. See the recvfrom description for more details.
676 length: Amount of data to read (in Bytes).
686 <h3>Return value:</h3>
687 buffer containing data successfully read
694 <li><a href="#Socket.recvfrom">
705 <dt><a name="Socket.recvfrom"></a><strong>Socket:recvfrom</strong> (length)</dt>
708 Receive a message on the socket including the senders source address.
715 length: Amount of data to read (in Bytes).
726 <li><strong>Warning:</strong> It is not guaranteed that all requested data
728 You have to check the return value - the length of the buffer actually read -
729 or use the safe IO functions in the high-level IO utility module.
731 <li>The length of the return buffer is limited by the (compile time)
732 nixio buffersize which is <em>nixio.const.buffersize</em> (8192 by default).
733 Any read request greater than that will be safely truncated to this value.
739 <h3>Return values:</h3>
742 <li>buffer containing data successfully read
744 <li>host IP-Address of the sender
746 <li>port Port of the sender
757 <dt><a name="Socket.send"></a><strong>Socket:send</strong> (buffer, offset, length)</dt>
760 Send a message on the socket.
761 This function is identical to sendto except for the missing destination
762 parameters. See the sendto description for a detailed description.
769 buffer: Buffer holding the data to be written.
773 offset: Offset to start reading the buffer from. (optional)
777 length: Length of chunk to read from the buffer. (optional)
787 <h3>Return value:</h3>
788 number of bytes written
795 <li><a href="#Socket.sendto">
806 <dt><a name="Socket.sendto"></a><strong>Socket:sendto</strong> (buffer, host, port, offset, length)</dt>
809 Send a message on the socket specifying the destination.
816 buffer: Buffer holding the data to be written.
820 host: Target IP-Address
828 offset: Offset to start reading the buffer from. (optional)
832 length: Length of chunk to read from the buffer. (optional)
843 <li><strong>Warning:</strong> It is not guaranteed that all data
844 in the buffer is written at once.
845 You have to check the return value - the number of bytes actually written -
846 or use the safe IO functions in the high-level IO utility module.
848 <li>Unlike standard Lua indexing the lowest offset and default is 0.
854 <h3>Return value:</h3>
855 number of bytes written
864 <dt><a name="Socket.setblocking"></a><strong>Socket:setblocking</strong> (blocking)</dt>
867 Set the blocking mode of the socket.
884 <h3>Return value:</h3>
894 <dt><a name="Socket.setopt"></a><strong>Socket:setopt</strong> (level, option, value)</dt>
904 level: Level ["socket", "tcp", "ip", "ipv6"]
908 option: Option ["keepalive", "reuseaddr", "sndbuf", "rcvbuf",
909 "priority", "broadcast", "linger", "sndtimeo", "rcvtimeo", "dontroute",
910 "bindtodevice", "error", "oobinline", "cork" (TCP), "nodelay" (TCP),
911 "mtu" (IP, IPv6), "hdrincl" (IP), "multicast_ttl" (IP), "multicast_loop"
912 (IP, IPv6), "multicast_if" (IP, IPv6), "v6only" (IPv6), "multicast_hops"
913 (IPv6), "add_membership" (IP, IPv6), "drop_membership" (IP, IPv6)]
927 <h3>Return value:</h3>
937 <dt><a name="Socket.shutdown"></a><strong>Socket:shutdown</strong> (how)</dt>
940 Shut down part of a full-duplex connection.
947 how: (optional, default: rdwr) ["rdwr", "rd", "wr"]
957 <h3>Return value:</h3>
967 <dt><a name="Socket.write"></a><strong>Socket:write</strong> (buffer, offset, length)</dt>
970 Send a message on the socket (This is an alias for send).
971 See the sendto description for a detailed description.
978 buffer: Buffer holding the data to be written.
982 offset: Offset to start reading the buffer from. (optional)
986 length: Length of chunk to read from the buffer. (optional)
996 <h3>Return value:</h3>
997 number of bytes written
1004 <li><a href="#Socket.sendto">
1019 </div> <!-- id="content" -->
1021 </div> <!-- id="main" -->
1024 <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>
1025 </div> <!-- id="about" -->
1027 </div> <!-- id="container" -->