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.protocol.html">luci.http.protocol</a>
46 <a href="../modules/luci.http.protocol.conditionals.html">luci.http.protocol.conditionals</a>
50 <a href="../modules/luci.http.protocol.date.html">luci.http.protocol.date</a>
54 <a href="../modules/luci.http.protocol.mime.html">luci.http.protocol.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.jsonc.html">luci.jsonc</a>
74 <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
78 <a href="../modules/luci.sys.init.html">luci.sys.init</a>
82 <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
86 <a href="../modules/luci.sys.net.html">luci.sys.net</a>
90 <a href="../modules/luci.sys.process.html">luci.sys.process</a>
94 <a href="../modules/luci.sys.user.html">luci.sys.user</a>
98 <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
102 <a href="../modules/nixio.html">nixio</a>
106 <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
110 <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
114 <a href="../modules/nixio.File.html">nixio.File</a>
118 <a href="../modules/nixio.README.html">nixio.README</a>
121 <li><strong>nixio.Socket</strong></li>
124 <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
128 <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
132 <a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
136 <a href="../modules/nixio.bin.html">nixio.bin</a>
140 <a href="../modules/nixio.bit.html">nixio.bit</a>
144 <a href="../modules/nixio.crypto.html">nixio.crypto</a>
148 <a href="../modules/nixio.fs.html">nixio.fs</a>
163 </div><!-- id="navigation" -->
167 <h1>Object Instance <code>nixio.Socket</code></h1>
171 Supports IPv4, IPv6 and UNIX (POSIX only) families.</p>
180 <table class="function_list">
183 <td class="name" nowrap><a href="#Socket.accept">Socket:accept</a> ()</td>
185 Accept a connection on the socket.</td>
189 <td class="name" nowrap><a href="#Socket.bind">Socket:bind</a> (host, port)</td>
191 Bind the socket to a network address.</td>
195 <td class="name" nowrap><a href="#Socket.close">Socket:close</a> ()</td>
197 Close the socket.</td>
201 <td class="name" nowrap><a href="#Socket.connect">Socket:connect</a> (host, port)</td>
203 Connect the socket to a network address.</td>
207 <td class="name" nowrap><a href="#Socket.fileno">Socket:fileno</a> ()</td>
209 Get the number of the filedescriptor.</td>
213 <td class="name" nowrap><a href="#Socket.getopt">Socket:getopt</a> (level, option)</td>
215 Get a socket option.</td>
219 <td class="name" nowrap><a href="#Socket.getpeername">Socket:getpeername</a> ()</td>
221 Get the peer address of a socket.</td>
225 <td class="name" nowrap><a href="#Socket.getsockname">Socket:getsockname</a> ()</td>
227 Get the local address of a socket.</td>
231 <td class="name" nowrap><a href="#Socket.listen">Socket:listen</a> (backlog)</td>
233 Listen for connections on the socket.</td>
237 <td class="name" nowrap><a href="#Socket.read ">Socket:read </a> (length)</td>
239 Receive a message on the socket (This is an alias for recv).</td>
243 <td class="name" nowrap><a href="#Socket.recv ">Socket:recv </a> (length)</td>
245 Receive a message on the socket.</td>
249 <td class="name" nowrap><a href="#Socket.recvfrom">Socket:recvfrom</a> (length)</td>
251 Receive a message on the socket including the senders source address.</td>
255 <td class="name" nowrap><a href="#Socket.send">Socket:send</a> (buffer, offset, length)</td>
257 Send a message on the socket.</td>
261 <td class="name" nowrap><a href="#Socket.sendto">Socket:sendto</a> (buffer, host, port, offset, length)</td>
263 Send a message on the socket specifying the destination.</td>
267 <td class="name" nowrap><a href="#Socket.setblocking">Socket:setblocking</a> (blocking)</td>
269 Set the blocking mode of the socket.</td>
273 <td class="name" nowrap><a href="#Socket.setopt">Socket:setopt</a> (level, option, value)</td>
275 Set a socket option.</td>
279 <td class="name" nowrap><a href="#Socket.shutdown">Socket:shutdown</a> (how)</td>
281 Shut down part of a full-duplex connection.</td>
285 <td class="name" nowrap><a href="#Socket.write">Socket:write</a> (buffer, offset, length)</td>
287 Send a message on the socket (This is an alias for send).</td>
301 <h2><a name="functions"></a>Functions</h2>
302 <dl class="function">
306 <dt><a name="Socket.accept"></a><strong>Socket:accept</strong> ()</dt>
309 Accept a connection on the socket.
317 <h3>Return values:</h3>
335 <dt><a name="Socket.bind"></a><strong>Socket:bind</strong> (host, port)</dt>
338 Bind the socket to a network address.
345 host: Host (optional, default: all addresses)
349 port: Port or service description
360 <li>This function calls getaddrinfo() and bind() but NOT listen().
362 <li>If <em>host</em> is a domain name it will be looked up and bind()
363 tries the IP-Addresses in the order returned by the DNS resolver
364 until the bind succeeds.
366 <li>UNIX sockets ignore the <em>port</em>,
367 and interpret <em>host</em> as a socket path.
373 <h3>Return value:</h3>
383 <dt><a name="Socket.close"></a><strong>Socket:close</strong> ()</dt>
394 <h3>Return value:</h3>
404 <dt><a name="Socket.connect"></a><strong>Socket:connect</strong> (host, port)</dt>
407 Connect the socket to a network address.
414 host: Hostname or IP-Address (optional, default: localhost)
418 port: Port or service description
429 <li>This function calls getaddrinfo() and connect().
431 <li>If <em>host</em> is a domain name it will be looked up and connect()
432 tries the IP-Addresses in the order returned by the DNS resolver
433 until the connect succeeds.
435 <li>UNIX sockets ignore the <em>port</em>,
436 and interpret <em>host</em> as a socket path.
442 <h3>Return value:</h3>
452 <dt><a name="Socket.fileno"></a><strong>Socket:fileno</strong> ()</dt>
455 Get the number of the filedescriptor.
463 <h3>Return value:</h3>
464 file descriptor number
473 <dt><a name="Socket.getopt"></a><strong>Socket:getopt</strong> (level, option)</dt>
483 level: Level ["socket", "tcp", "ip", "ipv6"]
487 option: Option ["keepalive", "reuseaddr", "sndbuf", "rcvbuf",
488 "priority", "broadcast", "linger", "sndtimeo", "rcvtimeo", "dontroute",
489 "bindtodevice", "error", "oobinline", "cork" (TCP), "nodelay" (TCP),
490 "mtu" (IP, IPv6), "hdrincl" (IP), "multicast_ttl" (IP), "multicast_loop"
491 (IP, IPv6), "multicast_if" (IP, IPv6), "v6only" (IPv6), "multicast_hops"
492 (IPv6), "add_membership" (IP, IPv6), "drop_membership" (IP, IPv6)]
502 <h3>Return value:</h3>
512 <dt><a name="Socket.getpeername"></a><strong>Socket:getpeername</strong> ()</dt>
515 Get the peer address of a socket.
523 <h3>Return values:</h3>
539 <dt><a name="Socket.getsockname"></a><strong>Socket:getsockname</strong> ()</dt>
542 Get the local address of a socket.
550 <h3>Return values:</h3>
566 <dt><a name="Socket.listen"></a><strong>Socket:listen</strong> (backlog)</dt>
569 Listen for connections on the socket.
576 backlog: Length of queue for pending connections
586 <h3>Return value:</h3>
596 <dt><a name="Socket.read "></a><strong>Socket:read </strong> (length)</dt>
599 Receive a message on the socket (This is an alias for recv).
600 See the recvfrom description for more details.
607 length: Amount of data to read (in Bytes).
617 <h3>Return value:</h3>
618 buffer containing data successfully read
625 <li><a href="#Socket.recvfrom">
636 <dt><a name="Socket.recv "></a><strong>Socket:recv </strong> (length)</dt>
639 Receive a message on the socket.
640 This function is identical to recvfrom except that it does not return
641 the sender's source address. See the recvfrom description for more details.
648 length: Amount of data to read (in Bytes).
658 <h3>Return value:</h3>
659 buffer containing data successfully read
666 <li><a href="#Socket.recvfrom">
677 <dt><a name="Socket.recvfrom"></a><strong>Socket:recvfrom</strong> (length)</dt>
680 Receive a message on the socket including the senders source address.
687 length: Amount of data to read (in Bytes).
698 <li><strong>Warning:</strong> It is not guaranteed that all requested data
700 You have to check the return value - the length of the buffer actually read -
701 or use the safe IO functions in the high-level IO utility module.
703 <li>The length of the return buffer is limited by the (compile time)
704 nixio buffersize which is <em>nixio.const.buffersize</em> (8192 by default).
705 Any read request greater than that will be safely truncated to this value.
711 <h3>Return values:</h3>
714 <li>buffer containing data successfully read
716 <li>host IP-Address of the sender
718 <li>port Port of the sender
729 <dt><a name="Socket.send"></a><strong>Socket:send</strong> (buffer, offset, length)</dt>
732 Send a message on the socket.
733 This function is identical to sendto except for the missing destination
734 paramters. See the sendto description for a detailed description.
741 buffer: Buffer holding the data to be written.
745 offset: Offset to start reading the buffer from. (optional)
749 length: Length of chunk to read from the buffer. (optional)
759 <h3>Return value:</h3>
760 number of bytes written
767 <li><a href="#Socket.sendto">
778 <dt><a name="Socket.sendto"></a><strong>Socket:sendto</strong> (buffer, host, port, offset, length)</dt>
781 Send a message on the socket specifying the destination.
788 buffer: Buffer holding the data to be written.
792 host: Target IP-Address
800 offset: Offset to start reading the buffer from. (optional)
804 length: Length of chunk to read from the buffer. (optional)
815 <li><strong>Warning:</strong> It is not guaranteed that all data
816 in the buffer is written at once.
817 You have to check the return value - the number of bytes actually written -
818 or use the safe IO functions in the high-level IO utility module.
820 <li>Unlike standard Lua indexing the lowest offset and default is 0.
826 <h3>Return value:</h3>
827 number of bytes written
836 <dt><a name="Socket.setblocking"></a><strong>Socket:setblocking</strong> (blocking)</dt>
839 Set the blocking mode of the socket.
856 <h3>Return value:</h3>
866 <dt><a name="Socket.setopt"></a><strong>Socket:setopt</strong> (level, option, value)</dt>
876 level: Level ["socket", "tcp", "ip", "ipv6"]
880 option: Option ["keepalive", "reuseaddr", "sndbuf", "rcvbuf",
881 "priority", "broadcast", "linger", "sndtimeo", "rcvtimeo", "dontroute",
882 "bindtodevice", "error", "oobinline", "cork" (TCP), "nodelay" (TCP),
883 "mtu" (IP, IPv6), "hdrincl" (IP), "multicast_ttl" (IP), "multicast_loop"
884 (IP, IPv6), "multicast_if" (IP, IPv6), "v6only" (IPv6), "multicast_hops"
885 (IPv6), "add_membership" (IP, IPv6), "drop_membership" (IP, IPv6)]
899 <h3>Return value:</h3>
909 <dt><a name="Socket.shutdown"></a><strong>Socket:shutdown</strong> (how)</dt>
912 Shut down part of a full-duplex connection.
919 how: (optional, default: rdwr) ["rdwr", "rd", "wr"]
929 <h3>Return value:</h3>
939 <dt><a name="Socket.write"></a><strong>Socket:write</strong> (buffer, offset, length)</dt>
942 Send a message on the socket (This is an alias for send).
943 See the sendto description for a detailed description.
950 buffer: Buffer holding the data to be written.
954 offset: Offset to start reading the buffer from. (optional)
958 length: Length of chunk to read from the buffer. (optional)
968 <h3>Return value:</h3>
969 number of bytes written
976 <li><a href="#Socket.sendto">
991 </div> <!-- id="content" -->
993 </div> <!-- id="main" -->
996 <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>
997 </div> <!-- id="about" -->
999 </div> <!-- id="container" -->