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
13       sockets. 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
27           arguments, these arguments are in key-value pairs.  "new" only
28           looks for one key "Domain" which tells new which domain the socket
29           will 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
41       supported "IO::Socket" methods, which are just front ends for the
42       corresponding 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
65           failure. In a list context a two-element array is returned
66           containing the new socket and the peer address; the list will be
67           empty upon 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()
96           function:
97
98                   use IO::Socket 'sockatmark';
99
100           This allows for a more traditional use of sockatmark() as a
101           procedural socket function.  If your system does not support
102           sockatmark(), 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
116           example, for an AF_INET socket the value of &AF_INET will be
117           returned.
118
119       sockopt(OPT [, VAL])
120           Unified method to both set and get options in the SOL_SOCKET level.
121           If called with one argument then getsockopt is called, otherwise
122           setsockopt is called.
123
124       getsockopt(LEVEL, OPT)
125           Get option associated with the socket. Other levels than SOL_SOCKET
126           may be specified here.
127
128       setsockopt(LEVEL, OPT, VAL)
129           Set option associated with the socket. Other levels than SOL_SOCKET
130           may be specified here.
131
132       socktype
133           Returns the numerical number for the socket type. For example, for
134           a SOCK_STREAM socket the value of &SOCK_STREAM will be returned.
135
136       timeout([VAL])
137           Set or get the timeout value (in seconds) associated with this
138           socket.  If called without any arguments then the current setting
139           is returned. If called with an argument the current setting is
140           changed and the previous value returned.
141

SEE ALSO

143       Socket, IO::Handle, IO::Socket::INET, IO::Socket::UNIX
144

AUTHOR

146       Graham Barr.  atmark() by Lincoln Stein.  Currently maintained by the
147       Perl Porters.  Please report all bugs to <perl5-porters@perl.org>.
148
150       Copyright (c) 1997-8 Graham Barr <gbarr@pobox.com>. All rights
151       reserved.  This program is free software; you can redistribute it
152       and/or modify it under the same terms as Perl itself.
153
154       The atmark() implementation: Copyright 2001, Lincoln Stein
155       <lstein@cshl.org>.  This module is distributed under the same terms as
156       Perl itself.  Feel free to use, modify and redistribute it as long as
157       you retain the correct attribution.
158
159
160
161perl v5.12.4                      2011-06-07                   IO::Socket(3pm)
Impressum