Install Perl 5.8.8
[msysgit.git] / mingw / html / lib / IO / Socket.html
blob9914a4be486f14ded9386fb698ac4f6d2afe2cd6
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>IO::Socket - Object interface to socket communications</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:" />
8 </head>
10 <body style="background-color: white">
11 <table border="0" width="100%" cellspacing="0" cellpadding="3">
12 <tr><td class="block" style="background-color: #cccccc" valign="middle">
13 <big><strong><span class="block">&nbsp;IO::Socket - Object interface to socket communications</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
22 <li><a href="#name">NAME</a></li>
23 <li><a href="#synopsis">SYNOPSIS</a></li>
24 <li><a href="#description">DESCRIPTION</a></li>
25 <li><a href="#constructor">CONSTRUCTOR</a></li>
26 <li><a href="#methods">METHODS</a></li>
27 <li><a href="#see_also">SEE ALSO</a></li>
28 <li><a href="#author">AUTHOR</a></li>
29 <li><a href="#copyright">COPYRIGHT</a></li>
30 </ul>
31 <!-- INDEX END -->
33 <hr />
34 <p>
35 </p>
36 <h1><a name="name">NAME</a></h1>
37 <p>IO::Socket - Object interface to socket communications</p>
38 <p>
39 </p>
40 <hr />
41 <h1><a name="synopsis">SYNOPSIS</a></h1>
42 <pre>
43 use IO::Socket;</pre>
44 <p>
45 </p>
46 <hr />
47 <h1><a name="description">DESCRIPTION</a></h1>
48 <p><code>IO::Socket</code> provides an object interface to creating and using sockets. It
49 is built upon the <a href="file://C|\msysgit\mingw\html/lib/IO/Handle.html">the IO::Handle manpage</a> interface and inherits all the methods defined
50 by <a href="file://C|\msysgit\mingw\html/lib/IO/Handle.html">the IO::Handle manpage</a>.</p>
51 <p><code>IO::Socket</code> only defines methods for those operations which are common to all
52 types of socket. Operations which are specified to a socket in a particular
53 domain have methods defined in sub classes of <code>IO::Socket</code></p>
54 <p><code>IO::Socket</code> will export all functions (and constants) defined by <a href="file://C|\msysgit\mingw\html/lib/Socket.html">the Socket manpage</a>.</p>
55 <p>
56 </p>
57 <hr />
58 <h1><a name="constructor">CONSTRUCTOR</a></h1>
59 <dl>
60 <dt><strong><a name="item_new">new ( [ARGS] )</a></strong>
62 <dd>
63 <p>Creates an <code>IO::Socket</code>, which is a reference to a
64 newly created symbol (see the <code>Symbol</code> package). <a href="#item_new"><code>new</code></a>
65 optionally takes arguments, these arguments are in key-value pairs.
66 <a href="#item_new"><code>new</code></a> only looks for one key <code>Domain</code> which tells new which domain
67 the socket will be in. All other arguments will be passed to the
68 configuration method of the package for that domain, See below.</p>
69 </dd>
70 <dd>
71 <pre>
72 NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE</pre>
73 </dd>
74 <dd>
75 <p>As of VERSION 1.18 all IO::Socket objects have autoflush turned on
76 by default. This was not the case with earlier releases.</p>
77 </dd>
78 <dd>
79 <pre>
80 NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE</pre>
81 </dd>
82 </li>
83 </dl>
84 <p>
85 </p>
86 <hr />
87 <h1><a name="methods">METHODS</a></h1>
88 <p>See <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html">the perlfunc manpage</a> for complete descriptions of each of the following
89 supported <code>IO::Socket</code> methods, which are just front ends for the
90 corresponding built-in functions:</p>
91 <pre>
92 socket
93 socketpair
94 bind
95 listen
96 accept
97 send
98 recv
99 peername (getpeername)
100 sockname (getsockname)
101 shutdown</pre>
102 <p>Some methods take slightly different arguments to those defined in <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html">the perlfunc manpage</a>
103 in attempt to make the interface more flexible. These are</p>
104 <dl>
105 <dt><strong><a name="item_accept"><code>accept([PKG])</code></a></strong>
107 <dd>
108 <p>perform the system call <a href="#item_accept"><code>accept</code></a> on the socket and return a new
109 object. The new object will be created in the same class as the listen
110 socket, unless <code>PKG</code> is specified. This object can be used to
111 communicate with the client that was trying to connect.</p>
112 </dd>
113 <dd>
114 <p>In a scalar context the new socket is returned, or undef upon
115 failure. In a list context a two-element array is returned containing
116 the new socket and the peer address; the list will be empty upon
117 failure.</p>
118 </dd>
119 <dd>
120 <p>The timeout in the [PKG] can be specified as zero to effect a ``poll'',
121 but you shouldn't do that because a new IO::Select object will be
122 created behind the scenes just to do the single poll. This is
123 horrendously inefficient. Use rather true <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_select"><code>select()</code></a> with a zero
124 timeout on the handle, or non-blocking IO.</p>
125 </dd>
126 </li>
127 <dt><strong><a name="item_socketpair">socketpair(DOMAIN, TYPE, PROTOCOL)</a></strong>
129 <dd>
130 <p>Call <a href="#item_socketpair"><code>socketpair</code></a> and return a list of two sockets created, or an
131 empty list on failure.</p>
132 </dd>
133 </li>
134 </dl>
135 <p>Additional methods that are provided are:</p>
136 <dl>
137 <dt><strong><a name="item_atmark">atmark</a></strong>
139 <dd>
140 <p>True if the socket is currently positioned at the urgent data mark,
141 false otherwise.</p>
142 </dd>
143 <dd>
144 <pre>
145 use IO::Socket;</pre>
146 </dd>
147 <dd>
148 <pre>
149 my $sock = IO::Socket::INET-&gt;new('some_server');
150 $sock-&gt;read($data, 1024) until $sock-&gt;atmark;</pre>
151 </dd>
152 <dd>
153 <p>Note: this is a reasonably new addition to the family of socket
154 functions, so all systems may not support this yet. If it is
155 unsupported by the system, an attempt to use this method will
156 abort the program.</p>
157 </dd>
158 <dd>
159 <p>The <a href="#item_atmark"><code>atmark()</code></a> functionality is also exportable as <code>sockatmark()</code> function:</p>
160 </dd>
161 <dd>
162 <pre>
163 use IO::Socket 'sockatmark';</pre>
164 </dd>
165 <dd>
166 <p>This allows for a more traditional use of <code>sockatmark()</code> as a procedural
167 socket function. If your system does not support sockatmark(), the
168 <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_use"><code>use</code></a> declaration will fail at compile time.</p>
169 </dd>
170 </li>
171 <dt><strong><a name="item_connected">connected</a></strong>
173 <dd>
174 <p>If the socket is in a connected state the peer address is returned.
175 If the socket is not in a connected state then undef will be returned.</p>
176 </dd>
177 </li>
178 <dt><strong><a name="item_protocol">protocol</a></strong>
180 <dd>
181 <p>Returns the numerical number for the protocol being used on the socket, if
182 known. If the protocol is unknown, as with an AF_UNIX socket, zero
183 is returned.</p>
184 </dd>
185 </li>
186 <dt><strong><a name="item_sockdomain">sockdomain</a></strong>
188 <dd>
189 <p>Returns the numerical number for the socket domain type. For example, for
190 an AF_INET socket the value of &amp;AF_INET will be returned.</p>
191 </dd>
192 </li>
193 <dt><strong><a name="item_sockopt">sockopt(OPT [, VAL])</a></strong>
195 <dd>
196 <p>Unified method to both set and get options in the SOL_SOCKET level. If called
197 with one argument then getsockopt is called, otherwise setsockopt is called.</p>
198 </dd>
199 </li>
200 <dt><strong><a name="item_socktype">socktype</a></strong>
202 <dd>
203 <p>Returns the numerical number for the socket type. For example, for
204 a SOCK_STREAM socket the value of &amp;SOCK_STREAM will be returned.</p>
205 </dd>
206 </li>
207 <dt><strong><a name="item_timeout"><code>timeout([VAL])</code></a></strong>
209 <dd>
210 <p>Set or get the timeout value associated with this socket. If called without
211 any arguments then the current setting is returned. If called with an argument
212 the current setting is changed and the previous value returned.</p>
213 </dd>
214 </li>
215 </dl>
217 </p>
218 <hr />
219 <h1><a name="see_also">SEE ALSO</a></h1>
220 <p><a href="file://C|\msysgit\mingw\html/lib/Socket.html">the Socket manpage</a>, <a href="file://C|\msysgit\mingw\html/lib/IO/Handle.html">the IO::Handle manpage</a>, <a href="file://C|\msysgit\mingw\html/lib/IO/Socket/INET.html">the IO::Socket::INET manpage</a>, <a href="file://C|\msysgit\mingw\html/lib/IO/Socket/UNIX.html">the IO::Socket::UNIX manpage</a></p>
222 </p>
223 <hr />
224 <h1><a name="author">AUTHOR</a></h1>
225 <p>Graham Barr. <a href="#item_atmark"><code>atmark()</code></a> by Lincoln Stein. Currently maintained by the
226 Perl Porters. Please report all bugs to &lt;<a href="mailto:perl5-porters@perl.org">perl5-porters@perl.org</a>&gt;.</p>
228 </p>
229 <hr />
230 <h1><a name="copyright">COPYRIGHT</a></h1>
231 <p>Copyright (c) 1997-8 Graham Barr &lt;<a href="mailto:gbarr@pobox.com">gbarr@pobox.com</a>&gt;. All rights reserved.
232 This program is free software; you can redistribute it and/or
233 modify it under the same terms as Perl itself.</p>
234 <p>The <a href="#item_atmark"><code>atmark()</code></a> implementation: Copyright 2001, Lincoln Stein &lt;<a href="mailto:lstein@cshl.org">lstein@cshl.org</a>&gt;.
235 This module is distributed under the same terms as Perl itself.
236 Feel free to use, modify and redistribute it as long as you retain
237 the correct attribution.</p>
238 <table border="0" width="100%" cellspacing="0" cellpadding="3">
239 <tr><td class="block" style="background-color: #cccccc" valign="middle">
240 <big><strong><span class="block">&nbsp;IO::Socket - Object interface to socket communications</span></strong></big>
241 </td></tr>
242 </table>
244 </body>
246 </html>