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

SEE ALSO

122       Socket, IO::Socket
123

AUTHOR

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