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

NAME

6       IO::Socket - Object interface to socket communications
7

SYNOPSIS

9           use IO::Socket;
10

DESCRIPTION

12       "IO::Socket" provides an object interface to creating and using sock‐
13       ets. It is built upon the IO::Handle interface and inherits all the
14       methods defined by IO::Handle.
15
16       "IO::Socket" only defines methods for those operations which are common
17       to all types of socket. Operations which are specified to a socket in a
18       particular domain have methods defined in sub classes of "IO::Socket"
19
20       "IO::Socket" will export all functions (and constants) defined by
21       Socket.
22

CONSTRUCTOR

24       new ( [ARGS] )
25           Creates an "IO::Socket", which is a reference to a newly created
26           symbol (see the "Symbol" package). "new" optionally takes argu‐
27           ments, these arguments are in key-value pairs.  "new" only looks
28           for one key "Domain" which tells new which domain the socket will
29           be in. All other arguments will be passed to the configuration
30           method of the package for that domain, See below.
31
32            NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
33
34           As of VERSION 1.18 all IO::Socket objects have autoflush turned on
35           by default. This was not the case with earlier releases.
36
37            NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
38

METHODS

40       See perlfunc for complete descriptions of each of the following sup‐
41       ported "IO::Socket" methods, which are just front ends for the corre‐
42       sponding built-in functions:
43
44           socket
45           socketpair
46           bind
47           listen
48           accept
49           send
50           recv
51           peername (getpeername)
52           sockname (getsockname)
53           shutdown
54
55       Some methods take slightly different arguments to those defined in
56       perlfunc in attempt to make the interface more flexible. These are
57
58       accept([PKG])
59           perform the system call "accept" on the socket and return a new
60           object. The new object will be created in the same class as the
61           listen socket, unless "PKG" is specified. This object can be used
62           to communicate with the client that was trying to connect.
63
64           In a scalar context the new socket is returned, or undef upon fail‐
65           ure. In a list context a two-element array is returned containing
66           the new socket and the peer address; the list will be empty upon
67           failure.
68
69           The timeout in the [PKG] can be specified as zero to effect a
70           "poll", but you shouldn't do that because a new IO::Select object
71           will be created behind the scenes just to do the single poll.  This
72           is horrendously inefficient.  Use rather true select() with a zero
73           timeout on the handle, or non-blocking IO.
74
75       socketpair(DOMAIN, TYPE, PROTOCOL)
76           Call "socketpair" and return a list of two sockets created, or an
77           empty list on failure.
78
79       Additional methods that are provided are:
80
81       atmark
82           True if the socket is currently positioned at the urgent data mark,
83           false otherwise.
84
85               use IO::Socket;
86
87               my $sock = IO::Socket::INET->new('some_server');
88               $sock->read($data, 1024) until $sock->atmark;
89
90           Note: this is a reasonably new addition to the family of socket
91           functions, so all systems may not support this yet.  If it is
92           unsupported by the system, an attempt to use this method will abort
93           the program.
94
95           The atmark() functionality is also exportable as sockatmark() func‐
96           tion:
97
98                   use IO::Socket 'sockatmark';
99
100           This allows for a more traditional use of sockatmark() as a proce‐
101           dural socket function.  If your system does not support sockat‐
102           mark(), the "use" declaration will fail at compile time.
103
104       connected
105           If the socket is in a connected state the peer address is returned.
106           If the socket is not in a connected state then undef will be
107           returned.
108
109       protocol
110           Returns the numerical number for the protocol being used on the
111           socket, if known. If the protocol is unknown, as with an AF_UNIX
112           socket, zero is returned.
113
114       sockdomain
115           Returns the numerical number for the socket domain type. For exam‐
116           ple, for an AF_INET socket the value of &AF_INET will be returned.
117
118       sockopt(OPT [, VAL])
119           Unified method to both set and get options in the SOL_SOCKET level.
120           If called with one argument then getsockopt is called, otherwise
121           setsockopt is called.
122
123       socktype
124           Returns the numerical number for the socket type. For example, for
125           a SOCK_STREAM socket the value of &SOCK_STREAM will be returned.
126
127       timeout([VAL])
128           Set or get the timeout value associated with this socket. If called
129           without any arguments then the current setting is returned. If
130           called with an argument the current setting is changed and the pre‐
131           vious value returned.
132

SEE ALSO

134       Socket, IO::Handle, IO::Socket::INET, IO::Socket::UNIX
135

AUTHOR

137       Graham Barr.  atmark() by Lincoln Stein.  Currently maintained by the
138       Perl Porters.  Please report all bugs to <perl5-porters@perl.org>.
139
141       Copyright (c) 1997-8 Graham Barr <gbarr@pobox.com>. All rights
142       reserved.  This program is free software; you can redistribute it
143       and/or modify it under the same terms as Perl itself.
144
145       The atmark() implementation: Copyright 2001, Lincoln Stein
146       <lstein@cshl.org>.  This module is distributed under the same terms as
147       Perl itself.  Feel free to use, modify and redistribute it as long as
148       you retain the correct attribution.
149
150
151
152perl v5.8.8                       2001-09-21                   IO::Socket(3pm)
Impressum