|
LWP::Socket - TCP/IP socket interface |
LWP::Socket - TCP/IP socket interface
$socket = new LWP::Socket;
$socket->connect('localhost', 7); # echo
$quote = 'I dunno, I dream in Perl sometimes...';
$socket->write("$quote\n");
$socket->read_until("\n", \$buffer);
$socket->read(\$buffer);
$socket = undef; # close
Beware: New code should not use this module. The IO::Socket::INET module provide the standard Perl interface to OO Internet sockets. Even LWP is now rewritten to use IO::Socket::INET throughout.
This class implements TCP/IP sockets. It groups socket generation, TCP address manipulation and buffered reading. Errors are handled by dying (throws exceptions).
Running this module standalone executes a self test which requires localhost to serve chargen and echo protocols.
The following methods are available:
shutdown()listen($queuesize)accept($timeout)getsockname()Note that $delim is discarded from the data returned.
pushback($data)If data is a reference to a subroutine, then we will call this routine to obtain the data to be written. The routine will be called until it returns undef or empty data. Data might be returned from the callback as a scalar or as a reference to a scalar.
Write returns the number of bytes written to the socket.
name argument for connect() or bind(). Might return
several addresses in array context if the hostname is bound to several
IP addresses.
This self test is only executed when this file is run standalone. It tests its functions against some standard TCP services implemented by inetd. If you do not have them around the tests will fail.
|
LWP::Socket - TCP/IP socket interface |