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">
5 <title>IO::Socket::INET - Object interface for AF_INET domain sockets
</title>
6 <meta http-equiv=
"content-type" content=
"text/html; charset=utf-8" />
7 <link rev=
"made" href=
"mailto:" />
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"> IO::Socket::INET - Object interface for AF_INET domain sockets
</span></strong></big>
17 <p><a name=
"__index__"></a></p>
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>
28 <li><a href=
"#methods">METHODS
</a></li>
31 <li><a href=
"#see_also">SEE ALSO
</a></li>
32 <li><a href=
"#author">AUTHOR
</a></li>
33 <li><a href=
"#copyright">COPYRIGHT
</a></li>
40 <h1><a name=
"name">NAME
</a></h1>
41 <p>IO::Socket::INET - Object interface for AF_INET domain sockets
</p>
45 <h1><a name=
"synopsis">SYNOPSIS
</a></h1>
47 use IO::Socket::INET;
</pre>
51 <h1><a name=
"description">DESCRIPTION
</a></h1>
52 <p><code>IO::Socket::INET
</code> provides an object interface to creating and using sockets
53 in the AF_INET domain. It is built upon the
<a href=
"file://C|\msysgit\mingw\html/lib/IO/Socket.html">the IO::Socket manpage
</a> interface and
54 inherits all the methods defined by
<a href=
"file://C|\msysgit\mingw\html/lib/IO/Socket.html">the IO::Socket manpage
</a>.
</p>
58 <h1><a name=
"constructor">CONSTRUCTOR
</a></h1>
60 <dt><strong><a name=
"item_new">new ( [ARGS] )
</a></strong>
63 <p>Creates an
<code>IO::Socket::INET
</code> object, 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.
</p>
68 <p>In addition to the key-value pairs accepted by
<a href=
"file://C|\msysgit\mingw\html/lib/IO/Socket.html">the IO::Socket manpage
</a>,
69 <code>IO::Socket::INET
</code> provides.
</p>
73 PeerAddr Remote host address
<hostname
>[:
<port
>]
74 PeerHost Synonym for PeerAddr
75 PeerPort Remote port or service
<service
>[(
<no
>)] |
<no
>
76 LocalAddr Local host bind address hostname[:port]
77 LocalHost Synonym for LocalAddr
78 LocalPort Local host bind port
<service
>[(
<no
>)] |
<no
>
79 Proto Protocol name (or number)
"tcp
" |
"udp
" | ...
80 Type Socket type SOCK_STREAM | SOCK_DGRAM | ...
81 Listen Queue size for listen
82 ReuseAddr Set SO_REUSEADDR before binding
83 Reuse Set SO_REUSEADDR before binding (deprecated, prefer ReuseAddr)
84 ReusePort Set SO_REUSEPORT before binding
85 Broadcast Set SO_BROADCAST before binding
86 Timeout Timeout value for various operations
87 MultiHomed Try all addresses for multi-homed hosts
88 Blocking Determine if connection will be blocking mode
</pre>
91 <p>If
<code>Listen
</code> is defined then a listen socket is created, else if the
92 socket type, which is derived from the protocol, is SOCK_STREAM then
93 <code>connect()
</code> is called.
</p>
96 <p>Although it is not illegal, the use of
<code>MultiHomed
</code> on a socket
97 which is in non-blocking mode is of little use. This is because the
98 first connect will never fail with a timeout as the connect call
102 <p>The
<code>PeerAddr
</code> can be a hostname or the IP-address on the
103 ``xx.xx.xx.xx'' form. The
<code>PeerPort
</code> can be a number or a symbolic
104 service name. The service name might be followed by a number in
105 parenthesis which is used if the service is not known by the system.
106 The
<code>PeerPort
</code> specification can also be embedded in the
<code>PeerAddr
</code>
107 by preceding it with a ``:''.
</p>
110 <p>If
<code>Proto
</code> is not given and you specify a symbolic
<code>PeerPort
</code> port,
111 then the constructor will try to derive
<code>Proto
</code> from the service
112 name. As a last resort
<code>Proto
</code> ``tcp'' is assumed. The
<code>Type
</code>
113 parameter will be deduced from
<code>Proto
</code> if not specified.
</p>
116 <p>If the constructor is only passed a single argument, it is assumed to
117 be a
<code>PeerAddr
</code> specification.
</p>
120 <p>If
<code>Blocking
</code> is set to
0, the connection will be in nonblocking mode.
121 If not specified it defaults to
1 (blocking mode).
</p>
128 $sock = IO::Socket::INET-
>new(PeerAddr =
> 'www.perl.org',
129 PeerPort =
> 'http(
80)',
130 Proto =
> 'tcp');
</pre>
134 $sock = IO::Socket::INET-
>new(PeerAddr =
> 'localhost:smtp(
25)');
</pre>
138 $sock = IO::Socket::INET-
>new(Listen =
> 5,
139 LocalAddr =
> 'localhost',
140 LocalPort =
> 9000,
141 Proto =
> 'tcp');
</pre>
145 $sock = IO::Socket::INET-
>new('
127.0.0.1:
25');
</pre>
149 $sock = IO::Socket::INET-
>new(PeerPort =
> 9999,
150 PeerAddr =
> inet_ntoa(INADDR_BROADCAST),
152 LocalAddr =
> 'localhost',
154 or die
"Can't bind : $@\n
";
</pre>
158 NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
</pre>
161 <p>As of VERSION
1.18 all IO::Socket objects have autoflush turned on
162 by default. This was not the case with earlier releases.
</p>
166 NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
</pre>
172 <h2><a name=
"methods">METHODS
</a></h2>
174 <dt><strong><a name=
"item_sockaddr">sockaddr ()
</a></strong>
177 <p>Return the address part of the sockaddr structure for the socket
</p>
180 <dt><strong><a name=
"item_sockport">sockport ()
</a></strong>
183 <p>Return the port number that the socket is using on the local host
</p>
186 <dt><strong><a name=
"item_sockhost">sockhost ()
</a></strong>
189 <p>Return the address part of the sockaddr structure for the socket in a
190 text form xx.xx.xx.xx
</p>
193 <dt><strong><a name=
"item_peeraddr">peeraddr ()
</a></strong>
196 <p>Return the address part of the sockaddr structure for the socket on
200 <dt><strong><a name=
"item_peerport">peerport ()
</a></strong>
203 <p>Return the port number for the socket on the peer host.
</p>
206 <dt><strong><a name=
"item_peerhost">peerhost ()
</a></strong>
209 <p>Return the address part of the sockaddr structure for the socket on the
210 peer host in a text form xx.xx.xx.xx
</p>
217 <h1><a name=
"see_also">SEE ALSO
</a></h1>
218 <p><a href=
"file://C|\msysgit\mingw\html/lib/Socket.html">the Socket manpage
</a>,
<a href=
"file://C|\msysgit\mingw\html/lib/IO/Socket.html">the IO::Socket manpage
</a></p>
222 <h1><a name=
"author">AUTHOR
</a></h1>
223 <p>Graham Barr. Currently maintained by the Perl Porters. Please report all
224 bugs to
<<a href=
"mailto:perl5-porters@perl.org">perl5-porters@perl.org
</a>>.
</p>
228 <h1><a name=
"copyright">COPYRIGHT
</a></h1>
229 <p>Copyright (c)
1996-
8 Graham Barr
<<a href=
"mailto:gbarr@pobox.com">gbarr@pobox.com
</a>>. All rights reserved.
230 This program is free software; you can redistribute it and/or
231 modify it under the same terms as Perl itself.
</p>
232 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
233 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
234 <big><strong><span class=
"block"> IO::Socket::INET - Object interface for AF_INET domain sockets
</span></strong></big>