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

SEE ALSO

124       Socket, IO::Socket
125

AUTHOR

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