@node IO/Socket, IPC/Open2, IO/Select, Module List
@unnumbered Object interface to socket communications


@unnumberedsec NAME

IO::Socket - Object interface to socket communications

@unnumberedsec SYNOPSIS

@example
use IO::Socket;
@end example

@unnumberedsec DESCRIPTION

@code{IO::Socket} provides an object interface to creating and using sockets. It
is built upon the @xref{IO/Handle,IO/Handle}, interface and inherits all the methods defined
by @xref{IO/Handle,IO/Handle},.

@code{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 @code{IO::Socket}

@unnumberedsec CONSTRUCTOR

@table @asis
@item new ( [ARGS] )
Creates a @code{IO::Pipe}, which is a reference to a
newly created symbol (see the Symbol package). new
optionally takes arguments, these arguments are in key-value pairs.
new only looks for one key @code{Domain} which tells new which domain
the socket it will be. All other arguments will be passed to the
configuration method of the package for that domain, See below.

@end table
@unnumberedsec METHODS

See @xref{(perl.info)perlfunc,Perlfunc}, for complete descriptions of each of the following
supported @code{IO::Seekable} methods, which are just front ends for the
corresponding built-in functions:

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

Some methods take slightly different arguments to those defined in @xref{(perl.info)perlfunc,Perlfunc},
in attempt to make the interface more flexible. These are

@table @asis
@item 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
@code{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

@item 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.

@item 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.

@item sockdomain
Returns the numerical number for the socket domain type. For example, fir
a AF_INET socket the value of &AF_INET will be returned.

@item socktype
Returns the numerical number for the socket type. For example, fir
a SOCK_STREAM socket the value of &SOCK_STREAM will be returned.

@item protocol
Returns the numerical number for the protocol being used on the socket, if
known. If the protocol is unknown, as with an AF_UNIX socket, zero
is returned.

@end table
@unnumberedsec SUB-CLASSES

@unnumberedsubsec 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

@example
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
@end example

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 @code{Proto} needs to be specified, one will be assumed
from the other.

@unnumberedsubsec METHODS

@table @asis
@item sockaddr ()
Return the address part of the sockaddr structure for the socket

@item sockport ()
Return the port number that the socket is using on the local host

@item sockhost ()
Return the address part of the sockaddr structure for the socket in a
text form xx.xx.xx.xx

@item peeraddr ()
Return the address part of the sockaddr structure for the socket on
the peer host

@item peerport ()
Return the port number for the socket on the peer host.

@item peerhost ()
Return the address part of the sockaddr structure for the socket on the
peer host in a text form xx.xx.xx.xx

@end table
@unnumberedsubsec 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

@example
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
@end example

@unnumberedsubsec METHODS

@table @asis
@item hostpath()
Returns the pathname to the fifo at the local end.

@item peerpath()
Returns the pathanme to the fifo at the peer end.

@end table
@unnumberedsec AUTHOR

Graham Barr <@file{Graham.Barr@@tiuk.ti.com}>

@unnumberedsec REVISION

$Revision: 1.13 $

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

@example
Revision 1.8   => VERSION 1.08
Revision 1.2.3 => VERSION 1.0203
@end example

@unnumberedsec 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.

