NAME

IO::Socket - supply object methods for sockets

SYNOPSIS

use IO::Socket;

DESCRIPTION

IO::Socket provides an object interface to creating and using sockets. It is built upon the IO::Handle interface and inherits all the methods defined by IO::Handle.

IO::Socket only defines methods for those operations which are common to all types of socket. Operations which are specified to a socket in a particular domain have methods defined in sub classes of IO::Socket

See perlfunc for complete descriptions of each of the following supported IO::Seekable methods, which are just front ends for the corresponding built-in functions:

socket
socketpair
bind
listen
accept
send
recv
peername (getpeername)
sockname (getsockname)

Some methods take slightly different arguments to those defined in perlfunc in attempt to make the interface more flexible. These are

accept([PKG])

perform the system call accept on the socket and return a new object. The new object will be created in the same class as the listen socket, unless PKG is specified. This object can be used to communicate with the client that was trying to connect. In a scalar context the new socket is returned, or undef upon failure. In an array context a two-element array is returned containing the new socket and the peer address, the list will be empty upon failure.

Additional methods that are provided are

timeout([VAL])

Set or get the timeout value associated with this socket. If called without any arguments then the current setting is returned. If called with an argument the current setting is changed and the previous value returned.

sockopt(OPT [, VAL])

Unified method to both set and get options in the SOL_SOCKET level. If called with one argument then getsockopt is called, otherwise setsockopt is called

SUB-CLASSES

IO::Socket::INET

IO::Socket::INET provides a constructor to create an AF_INET domain socket and some related methods. The constructor can take the following options

PeerAddr	Remote host address
PeerPort	Remote port or service
LocalPort	Local host bind	port
LocalAddr	Local host bind	address
Proto	Protocol name (eg tcp udp etc)
Type	Socket type (SOCK_STREAM etc)
Listen	Queue size for listen
Timeout	Timeout	value for various operations

If Listen is defined then a listen socket is created, else if the socket type, which is derived from the protocol, is SOCK_STREAM then a connect is called

Only one of Type or Proto needs to be specified, one will be assumed from the other.

METHODS

sockaddr()

Return the address part of the sockaddr structure for the socket

sockport()

Return the port number that the socket is using on the local host

sockhost()

Return the address part of the sockaddr structure for the socket in a text form xx.xx.xx.xx

peeraddr(), peerport(), peerhost()

Same as for the sock* functions, but returns the data about the peer host instead of the local host.

IO::Socket::UNIX

IO::Socket::UNIX provides a constructor to create an AF_UNIX domain socket and some related methods. The constructor can take the following options

Type    	Type of socket (eg SOCK_STREAM or SOCK_DGRAM)
Local   	Path to local fifo
Peer    	Path to peer fifo
Listen  	Create a listen socket

METHODS

hostpath()

Returns the pathname to the fifo at the local end

peerpath()

Returns the pathanme to the fifo at the peer end

AUTHOR

Graham Barr <Graham.Barr@tiuk.ti.com>

REVISION

$Revision: 1.9 $

The VERSION is derived from the revision turning each number after the first dot into a 2 digit number so

Revision 1.8   => VERSION 1.08
Revision 1.2.3 => VERSION 1.0203

COPYRIGHT

Copyright (c) 1995 Graham Barr. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

6 POD Errors

The following errors were encountered while parsing the POD:

Around line 40:

'=item' outside of any '=over'

Around line 281:

You forgot a '=back' before '=head1'

Around line 326:

'=item' outside of any '=over'

Around line 483:

You forgot a '=back' before '=head2'

Around line 495:

'=item' outside of any '=over'

Around line 542:

You forgot a '=back' before '=head1'