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.protocol.html">luci.http.protocol</a>
50 <a href="../modules/luci.http.protocol.conditionals.html">luci.http.protocol.conditionals</a>
54 <a href="../modules/luci.http.protocol.date.html">luci.http.protocol.date</a>
58 <a href="../modules/luci.http.protocol.mime.html">luci.http.protocol.mime</a>
62 <a href="../modules/luci.i18n.html">luci.i18n</a>
66 <a href="../modules/luci.ip.html">luci.ip</a>
70 <a href="../modules/luci.ip.cidr.html">luci.ip.cidr</a>
74 <a href="../modules/luci.json.html">luci.json</a>
78 <a href="../modules/luci.jsonc.html">luci.jsonc</a>
82 <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
86 <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
90 <a href="../modules/luci.model.uci.html">luci.model.uci</a>
94 <a href="../modules/luci.rpcc.html">luci.rpcc</a>
98 <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
102 <a href="../modules/luci.sys.html">luci.sys</a>
106 <a href="../modules/luci.sys.init.html">luci.sys.init</a>
110 <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
114 <a href="../modules/luci.sys.net.html">luci.sys.net</a>
118 <a href="../modules/luci.sys.process.html">luci.sys.process</a>
122 <a href="../modules/luci.sys.user.html">luci.sys.user</a>
126 <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
130 <a href="../modules/luci.util.html">luci.util</a>
134 <a href="../modules/nixio.html">nixio</a>
138 <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
142 <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
146 <a href="../modules/nixio.File.html">nixio.File</a>
150 <a href="../modules/nixio.README.html">nixio.README</a>
153 <li><strong>nixio.Socket</strong></li>
156 <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
160 <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
164 <a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
168 <a href="../modules/nixio.bin.html">nixio.bin</a>
172 <a href="../modules/nixio.bit.html">nixio.bit</a>
176 <a href="../modules/nixio.crypto.html">nixio.crypto</a>
180 <a href="../modules/nixio.fs.html">nixio.fs</a>
195 </div><!-- id="navigation" -->
199 <h1>Object Instance <code>nixio.Socket</code></h1>
203 Supports IPv4, IPv6 and UNIX (POSIX only) families.</p>
212 <table class="function_list">
215 <td class="name" nowrap><a href="#Socket.accept">Socket:accept</a> ()</td>
217 Accept a connection on the socket.</td>
221 <td class="name" nowrap><a href="#Socket.bind">Socket:bind</a> (host, port)</td>
223 Bind the socket to a network address.</td>
227 <td class="name" nowrap><a href="#Socket.close">Socket:close</a> ()</td>
229 Close the socket.</td>
233 <td class="name" nowrap><a href="#Socket.connect">Socket:connect</a> (host, port)</td>
235 Connect the socket to a network address.</td>
239 <td class="name" nowrap><a href="#Socket.fileno">Socket:fileno</a> ()</td>
241 Get the number of the filedescriptor.</td>
245 <td class="name" nowrap><a href="#Socket.getopt">Socket:getopt</a> (level, option)</td>
247 Get a socket option.</td>
251 <td class="name" nowrap><a href="#Socket.getpeername">Socket:getpeername</a> ()</td>
253 Get the peer address of a socket.</td>
257 <td class="name" nowrap><a href="#Socket.getsockname">Socket:getsockname</a> ()</td>
259 Get the local address of a socket.</td>
263 <td class="name" nowrap><a href="#Socket.listen">Socket:listen</a> (backlog)</td>
265 Listen for connections on the socket.</td>
269 <td class="name" nowrap><a href="#Socket.read ">Socket:read </a> (length)</td>
271 Receive a message on the socket (This is an alias for recv).</td>
275 <td class="name" nowrap><a href="#Socket.recv ">Socket:recv </a> (length)</td>
277 Receive a message on the socket.</td>
281 <td class="name" nowrap><a href="#Socket.recvfrom">Socket:recvfrom</a> (length)</td>
283 Receive a message on the socket including the senders source address.</td>
287 <td class="name" nowrap><a href="#Socket.send">Socket:send</a> (buffer, offset, length)</td>
289 Send a message on the socket.</td>
293 <td class="name" nowrap><a href="#Socket.sendto">Socket:sendto</a> (buffer, host, port, offset, length)</td>
295 Send a message on the socket specifying the destination.</td>
299 <td class="name" nowrap><a href="#Socket.setblocking">Socket:setblocking</a> (blocking)</td>
301 Set the blocking mode of the socket.</td>
305 <td class="name" nowrap><a href="#Socket.setopt">Socket:setopt</a> (level, option, value)</td>
307 Set a socket option.</td>
311 <td class="name" nowrap><a href="#Socket.shutdown">Socket:shutdown</a> (how)</td>
313 Shut down part of a full-duplex connection.</td>
317 <td class="name" nowrap><a href="#Socket.write">Socket:write</a> (buffer, offset, length)</td>
319 Send a message on the socket (This is an alias for send).</td>
333 <h2><a name="functions"></a>Functions</h2>
334 <dl class="function">
338 <dt><a name="Socket.accept"></a><strong>Socket:accept</strong> ()</dt>
341 Accept a connection on the socket.
349 <h3>Return values:</h3>
367 <dt><a name="Socket.bind"></a><strong>Socket:bind</strong> (host, port)</dt>
370 Bind the socket to a network address.
377 host: Host (optional, default: all addresses)
381 port: Port or service description
392 <li>This function calls getaddrinfo() and bind() but NOT listen().
394 <li>If <em>host</em> is a domain name it will be looked up and bind()
395 tries the IP-Addresses in the order returned by the DNS resolver
396 until the bind succeeds.
398 <li>UNIX sockets ignore the <em>port</em>,
399 and interpret <em>host</em> as a socket path.
405 <h3>Return value:</h3>
415 <dt><a name="Socket.close"></a><strong>Socket:close</strong> ()</dt>
426 <h3>Return value:</h3>
436 <dt><a name="Socket.connect"></a><strong>Socket:connect</strong> (host, port)</dt>
439 Connect the socket to a network address.
446 host: Hostname or IP-Address (optional, default: localhost)
450 port: Port or service description
461 <li>This function calls getaddrinfo() and connect().
463 <li>If <em>host</em> is a domain name it will be looked up and connect()
464 tries the IP-Addresses in the order returned by the DNS resolver
465 until the connect succeeds.
467 <li>UNIX sockets ignore the <em>port</em>,
468 and interpret <em>host</em> as a socket path.
474 <h3>Return value:</h3>
484 <dt><a name="Socket.fileno"></a><strong>Socket:fileno</strong> ()</dt>
487 Get the number of the filedescriptor.
495 <h3>Return value:</h3>
496 file descriptor number
505 <dt><a name="Socket.getopt"></a><strong>Socket:getopt</strong> (level, option)</dt>
515 level: Level ["socket", "tcp", "ip", "ipv6"]
519 option: Option ["keepalive", "reuseaddr", "sndbuf", "rcvbuf",
520 "priority", "broadcast", "linger", "sndtimeo", "rcvtimeo", "dontroute",
521 "bindtodevice", "error", "oobinline", "cork" (TCP), "nodelay" (TCP),
522 "mtu" (IP, IPv6), "hdrincl" (IP), "multicast_ttl" (IP), "multicast_loop"
523 (IP, IPv6), "multicast_if" (IP, IPv6), "v6only" (IPv6), "multicast_hops"
524 (IPv6), "add_membership" (IP, IPv6), "drop_membership" (IP, IPv6)]
534 <h3>Return value:</h3>
544 <dt><a name="Socket.getpeername"></a><strong>Socket:getpeername</strong> ()</dt>
547 Get the peer address of a socket.
555 <h3>Return values:</h3>
571 <dt><a name="Socket.getsockname"></a><strong>Socket:getsockname</strong> ()</dt>
574 Get the local address of a socket.
582 <h3>Return values:</h3>
598 <dt><a name="Socket.listen"></a><strong>Socket:listen</strong> (backlog)</dt>
601 Listen for connections on the socket.
608 backlog: Length of queue for pending connections
618 <h3>Return value:</h3>
628 <dt><a name="Socket.read "></a><strong>Socket:read </strong> (length)</dt>
631 Receive a message on the socket (This is an alias for recv).
632 See the recvfrom description for more details.
639 length: Amount of data to read (in Bytes).
649 <h3>Return value:</h3>
650 buffer containing data successfully read
657 <li><a href="#Socket.recvfrom">
668 <dt><a name="Socket.recv "></a><strong>Socket:recv </strong> (length)</dt>
671 Receive a message on the socket.
672 This function is identical to recvfrom except that it does not return
673 the sender's source address. See the recvfrom description for more details.
680 length: Amount of data to read (in Bytes).
690 <h3>Return value:</h3>
691 buffer containing data successfully read
698 <li><a href="#Socket.recvfrom">
709 <dt><a name="Socket.recvfrom"></a><strong>Socket:recvfrom</strong> (length)</dt>
712 Receive a message on the socket including the senders source address.
719 length: Amount of data to read (in Bytes).
730 <li><strong>Warning:</strong> It is not guaranteed that all requested data
732 You have to check the return value - the length of the buffer actually read -
733 or use the safe IO functions in the high-level IO utility module.
735 <li>The length of the return buffer is limited by the (compile time)
736 nixio buffersize which is <em>nixio.const.buffersize</em> (8192 by default).
737 Any read request greater than that will be safely truncated to this value.
743 <h3>Return values:</h3>
746 <li>buffer containing data successfully read
748 <li>host IP-Address of the sender
750 <li>port Port of the sender
761 <dt><a name="Socket.send"></a><strong>Socket:send</strong> (buffer, offset, length)</dt>
764 Send a message on the socket.
765 This function is identical to sendto except for the missing destination
766 parameters. See the sendto description for a detailed description.
773 buffer: Buffer holding the data to be written.
777 offset: Offset to start reading the buffer from. (optional)
781 length: Length of chunk to read from the buffer. (optional)
791 <h3>Return value:</h3>
792 number of bytes written
799 <li><a href="#Socket.sendto">
810 <dt><a name="Socket.sendto"></a><strong>Socket:sendto</strong> (buffer, host, port, offset, length)</dt>
813 Send a message on the socket specifying the destination.
820 buffer: Buffer holding the data to be written.
824 host: Target IP-Address
832 offset: Offset to start reading the buffer from. (optional)
836 length: Length of chunk to read from the buffer. (optional)
847 <li><strong>Warning:</strong> It is not guaranteed that all data
848 in the buffer is written at once.
849 You have to check the return value - the number of bytes actually written -
850 or use the safe IO functions in the high-level IO utility module.
852 <li>Unlike standard Lua indexing the lowest offset and default is 0.
858 <h3>Return value:</h3>
859 number of bytes written
868 <dt><a name="Socket.setblocking"></a><strong>Socket:setblocking</strong> (blocking)</dt>
871 Set the blocking mode of the socket.
888 <h3>Return value:</h3>
898 <dt><a name="Socket.setopt"></a><strong>Socket:setopt</strong> (level, option, value)</dt>
908 level: Level ["socket", "tcp", "ip", "ipv6"]
912 option: Option ["keepalive", "reuseaddr", "sndbuf", "rcvbuf",
913 "priority", "broadcast", "linger", "sndtimeo", "rcvtimeo", "dontroute",
914 "bindtodevice", "error", "oobinline", "cork" (TCP), "nodelay" (TCP),
915 "mtu" (IP, IPv6), "hdrincl" (IP), "multicast_ttl" (IP), "multicast_loop"
916 (IP, IPv6), "multicast_if" (IP, IPv6), "v6only" (IPv6), "multicast_hops"
917 (IPv6), "add_membership" (IP, IPv6), "drop_membership" (IP, IPv6)]
931 <h3>Return value:</h3>
941 <dt><a name="Socket.shutdown"></a><strong>Socket:shutdown</strong> (how)</dt>
944 Shut down part of a full-duplex connection.
951 how: (optional, default: rdwr) ["rdwr", "rd", "wr"]
961 <h3>Return value:</h3>
971 <dt><a name="Socket.write"></a><strong>Socket:write</strong> (buffer, offset, length)</dt>
974 Send a message on the socket (This is an alias for send).
975 See the sendto description for a detailed description.
982 buffer: Buffer holding the data to be written.
986 offset: Offset to start reading the buffer from. (optional)
990 length: Length of chunk to read from the buffer. (optional)
1000 <h3>Return value:</h3>
1001 number of bytes written
1008 <li><a href="#Socket.sendto">
1023 </div> <!-- id="content" -->
1025 </div> <!-- id="main" -->
1028 <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>
1029 </div> <!-- id="about" -->
1031 </div> <!-- id="container" -->