📄 ch15_02.htm
字号:
</dd><dt><b><tt class="literal">LocalAddr =></tt> <em class="replaceable">hostname</em>[:<em class="replaceable">port</em>]</b></dt><dd><a name="INDEX-1961" />Specifies the localaddress (and optional port number) to bind to a server-side socket.</p></dd><dt><b><tt class="literal">LocalPort =></tt> <em class="replaceable">port</em></b></dt><dd><a name="INDEX-1962" />Specifies the local portnumber (or service name) to bind to a server-side socket.</p></dd><dt><b><tt class="literal">Proto =></tt> <em class="replaceable">name</em></b></dt><dd><a name="INDEX-1963" />Specifies the protocol tobe run on the socket, i.e., <tt class="literal">tcp</tt> or<tt class="literal">udp</tt>.</p></dd><dt><b><tt class="literal">Type => SOCK_STREAM | SOCK_DGRAM</tt></b></dt><dd><a name="INDEX-1964" />Specifies the type of socket.<tt class="literal">SOCK_STREAM</tt> indicates a stream-based socketconnection, and <tt class="literal">SOCK_DGRAM</tt> indicates amessage-based (datagram) connection.</p></dd><dt><b><tt class="literal">Listen =></tt> <em class="replaceable">n</em></b></dt><dd><a name="INDEX-1965" />Sets the listen-queue size to<em class="replaceable"><tt>n</tt></em> number of client requests.</p></dd><dt><b><tt class="literal">Reuse => 1</tt></b></dt><dd><a name="INDEX-1966" />Given a nonzero number,this option allows the local bind address to be reused should thesocket need to be reopened after an error.</p></dd><dt><b><tt class="literal">Timeout =></tt> <em class="replaceable">n</em></b></dt><dd><a name="INDEX-1967" />Sets the timeout.</p></dd></dl><p>Whether a server (receiving) or client (requesting) socket is createddepends on the parameters provided to the constructor. If<tt class="literal">Listen</tt> is defined, a server socket isautomatically created. If no protocol is specified, it is derivedfrom the service on the given port number. If no port number isgiven, <tt class="literal">tcp</tt> is used by default.</p><a name="perlnut2-CHP-15-SECT-2.4.1" /><div class="sect3"><h3 class="sect3">15.2.4.1. IO::Socket::INET methods</h3><p>The following methods can be used on socket filehandle objectscreated by IO::Socket::INET.</p><a name="INDEX-1968" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>peeraddr</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>peeraddr</pre><p><a name="INDEX-1968" />Returns the address part(packed string) of the socket-address data structure for the remotehost to which a socket connects.</p></div><a name="INDEX-1969" /><a name="INDEX-1970" /><a name="INDEX-1971" /><a name="INDEX-1972" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>peerhost</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>peerhost</pre><p><a name="INDEX-1969" />Returns the remote hostaddress in the dotted-quad string form, e.g., 207.44.27.2.<a name="INDEX-1970" /><a name="INDEX-1971" /><a name="INDEX-1972" /></p></div><a name="INDEX-1973" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>peerport</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>peerport</pre><p><a name="INDEX-1973" />Returns the port numberfor the remote host to which a socket connects.</p></div><a name="INDEX-1974" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>sockaddr</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>sockaddr</pre><p><a name="INDEX-1974" />Returns the address part(as a packed string) of the socket-address data structure for thesocket.</p></div><a name="INDEX-1975" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>sockhost</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>sockhost</pre><p><a name="INDEX-1975" />Returns the address partof the socket-address data structure in the dotted-quad string form,e.g., 207.44.27.2.</p></div><a name="INDEX-1976" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>sockport</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>sockport</pre><p><a name="INDEX-1976" />Returns the local portnumber for the socket.</p></div></div></div><a name="perlnut2-CHP-15-SECT-2.5" /><div class="sect2"><h3 class="sect2">15.2.5. IO::Socket::UNIX Reference</h3><p><a name="INDEX-1977" /><a name="INDEX-1978" /><a name="INDEX-1979" />The IO::Socket::UNIX subclass createsa Unix-domain socket. Unix-domain sockets are local to the currenthost and are used internally to implement pipes, thus providingcommunication between unrelated processes. Using sockets providesfiner control than using named pipes, also called FIFO (first-in,first-out) buffers. This is because receiving sockets can distinguishbetween different client connections, which can then be assigned todifferent sessions with the <tt class="literal">accept</tt> call.</p><p>The IO::Socket::UNIX constructor (<tt class="literal">new( )</tt>) createsthe socket and returns an object containing a filehandle. Theconstructor can take the following options:</p><dl><dt><b><tt class="literal">Type => SOCK_STREAM | SOCK_DGRAM</tt></b></dt><dd><a name="INDEX-1980" />Indicates the type of socket:<tt class="literal">SOCK_STREAM</tt> for streaming,<tt class="literal">SOCK_DGRAM</tt> for packets or datagrams.</p></dd><dt><b><tt class="literal">Local =></tt> <em class="replaceable">pathname</em></b></dt><dd><a name="INDEX-1981" />Provides the pathname ofthe FIFO buffer to bind to the socket.</p></dd><dt><b><tt class="literal">Peer =></tt> <em class="replaceable">pathname</em></b></dt><dd><a name="INDEX-1982" />Provides the pathname tothe destination FIFO buffer.</p></dd><dt><b><tt class="literal">Listen =></tt> <em class="replaceable">n</em></b></dt><dd><a name="INDEX-1983" />Creates a listen socket and sets thequeue size to <em class="replaceable"><tt>n</tt></em>.</p></dd></dl><p>The following methods can be used on an object created withIO::Socket::UNIX.</p><a name="INDEX-1984" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>hostpath</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>hostpath</pre><p><a name="INDEX-1984" />Returns the pathname tothe local FIFO buffer.</p></div><a name="INDEX-1985" /><a name="INDEX-1986" /><a name="INDEX-1987" /><a name="INDEX-1988" /><a name="INDEX-1989" /><a name="INDEX-1990" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>peerpath</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>peerpath</pre><p><a name="INDEX-1985" />Returns the pathname tothe destination or peer FIFO.<a name="INDEX-1986" /><a name="INDEX-1987" /><a name="INDEX-1988" /><a name="INDEX-1989" /><a name="INDEX-1990" /> </p></div></div><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch15_01.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0" /></a></td><td align="right" valign="top" width="228"><a href="ch16_01.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td align="left" valign="top" width="228">15. Sockets</td><td align="center" valign="top" width="228"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0" /></a></td><td align="right" valign="top" width="228">16. Email Connectivity</td></tr></table></div><hr width="684" align="left" /><img src="../gifs/navbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links" /><p><p><font size="-1"><a href="copyrght.htm">Copyright © 2002</a> O'Reilly & Associates. All rights reserved.</font></p><map name="library-map"><area shape="rect" coords="1,0,85,94" href="../index.htm"><area shape="rect" coords="86,1,178,103" href="../lwp/index.htm"><area shape="rect" coords="180,0,265,103" href="../lperl/index.htm"><area shape="rect" coords="267,0,353,105" href="../perlnut/index.htm"><area shape="rect" coords="354,1,446,115" href="../prog/index.htm"><area shape="rect" coords="448,0,526,132" href="../tk/index.htm"><area shape="rect" coords="528,1,615,119" href="../cookbook/index.htm"><area shape="rect" coords="617,0,690,135" href="../pxml/index.htm"></map></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -