1IO::Socket::INET(3pm)  Perl Programmers Reference Guide  IO::Socket::INET(3pm)
2
3
4

NAME

6       IO::Socket::INET - Object interface for AF_INET domain sockets
7

SYNOPSIS

9           use IO::Socket::INET;
10

DESCRIPTION

12       "IO::Socket::INET" provides an object interface to creating and using
13       sockets in the AF_INET domain. It is built upon the IO::Socket
14       interface and inherits all the methods defined by IO::Socket.
15

CONSTRUCTOR

17       new ( [ARGS] )
18           Creates an "IO::Socket::INET" object, which is a reference to a
19           newly created symbol (see the "Symbol" package). "new" optionally
20           takes arguments, these arguments are in key-value pairs.
21
22           In addition to the key-value pairs accepted by IO::Socket,
23           "IO::Socket::INET" provides.
24
25            PeerAddr    Remote host address          <hostname>[:<port>]
26            PeerHost    Synonym for PeerAddr
27            PeerPort    Remote port or service       <service>[(<no>)] | <no>
28            LocalAddr   Local host bind address      hostname[:port]
29            LocalHost   Synonym for LocalAddr
30            LocalPort   Local host bind port         <service>[(<no>)] | <no>
31            Proto       Protocol name (or number)    "tcp" | "udp" | ...
32            Type        Socket type              SOCK_STREAM | SOCK_DGRAM | ...
33            Listen      Queue size for listen
34            ReuseAddr   Set SO_REUSEADDR before binding
35            Reuse       Set SO_REUSEADDR before binding (deprecated,
36                                                         prefer ReuseAddr)
37            ReusePort   Set SO_REUSEPORT before binding
38            Broadcast   Set SO_BROADCAST before binding
39            Timeout     Timeout value for various operations
40            MultiHomed  Try all addresses for multi-homed hosts
41            Blocking    Determine if connection will be blocking mode
42
43           If "Listen" is defined then a listen socket is created, else if the
44           socket type, which is derived from the protocol, is SOCK_STREAM
45           then connect() is called.
46
47           Although it is not illegal, the use of "MultiHomed" on a socket
48           which is in non-blocking mode is of little use. This is because the
49           first connect will never fail with a timeout as the connect call
50           will not block.
51
52           The "PeerAddr" can be a hostname or the IP-address on the
53           "xx.xx.xx.xx" form.  The "PeerPort" can be a number or a symbolic
54           service name.  The service name might be followed by a number in
55           parenthesis which is used if the service is not known by the
56           system.  The "PeerPort" specification can also be embedded in the
57           "PeerAddr" by preceding it with a ":".
58
59           If "Proto" is not given and you specify a symbolic "PeerPort" port,
60           then the constructor will try to derive "Proto" from the service
61           name.  As a last resort "Proto" "tcp" is assumed.  The "Type"
62           parameter will be deduced from "Proto" if not specified.
63
64           If the constructor is only passed a single argument, it is assumed
65           to be a "PeerAddr" specification.
66
67           If "Blocking" is set to 0, the connection will be in nonblocking
68           mode.  If not specified it defaults to 1 (blocking mode).
69
70           Examples:
71
72              $sock = IO::Socket::INET->new(PeerAddr => 'www.perl.org',
73                                            PeerPort => 'http(80)',
74                                            Proto    => 'tcp');
75
76              $sock = IO::Socket::INET->new(PeerAddr => 'localhost:smtp(25)');
77
78              $sock = IO::Socket::INET->new(Listen    => 5,
79                                            LocalAddr => 'localhost',
80                                            LocalPort => 9000,
81                                            Proto     => 'tcp');
82
83              $sock = IO::Socket::INET->new('127.0.0.1:25');
84
85              $sock = IO::Socket::INET->new(
86                                      PeerPort  => 9999,
87                                      PeerAddr  => inet_ntoa(INADDR_BROADCAST),
88                                      Proto     => udp,
89                                      LocalAddr => 'localhost',
90                                      Broadcast => 1 )
91                                  or die "Can't bind : $@\n";
92
93            NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
94
95           As of VERSION 1.18 all IO::Socket objects have autoflush turned on
96           by default. This was not the case with earlier releases.
97
98            NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
99
100   METHODS
101       sockaddr ()
102           Return the address part of the sockaddr structure for the socket
103
104       sockport ()
105           Return the port number that the socket is using on the local host
106
107       sockhost ()
108           Return the address part of the sockaddr structure for the socket in
109           a text form xx.xx.xx.xx
110
111       peeraddr ()
112           Return the address part of the sockaddr structure for the socket on
113           the peer host
114
115       peerport ()
116           Return the port number for the socket on the peer host.
117
118       peerhost ()
119           Return the address part of the sockaddr structure for the socket on
120           the peer host in a text form xx.xx.xx.xx
121

SEE ALSO

123       Socket, IO::Socket
124

AUTHOR

126       Graham Barr. Currently maintained by the Perl Porters.  Please report
127       all bugs to <perlbug@perl.org>.
128
130       Copyright (c) 1996-8 Graham Barr <gbarr@pobox.com>. All rights
131       reserved.  This program is free software; you can redistribute it
132       and/or modify it under the same terms as Perl itself.
133
134
135
136perl v5.16.3                      2013-03-04             IO::Socket::INET(3pm)
Impressum