NAME
Net::TCP - TCP sockets interface module
SYNOPSIS
use Socket; # optional
use Net::Gen; # optional
use Net::Inet; # optional
use Net::TCP;
DESCRIPTION
The Net::TCP
module provides services for TCP communications over sockets. It is layered atop the Net::Inet
and Net::Gen
modules, which are part of the same distribution.
Public Methods
The following methods are provided by the Net::TCP
module itself, rather than just being inherited from Net::Inet
or Net::Gen
.
- new
-
Usage:
$obj = new Net::TCP; $obj = new Net::TCP $host, $service; $obj = new Net::TCP \%parameters; $obj = new Net::TCP $host, $service, \%parameters;
Returns a newly-initialised object of the given class. If called for a derived class, no validation of the supplied parameters will be performed. (This is so that the derived class can add the parameter validation it needs to the object before allowing the validation.) Otherwise, it will cause the parameters to be validated by calling its
init
method, whichNet::TCP
inherits fromNet::Inet
. In particular, this means that if both a host and a service are given, then an object will only be returned if a connect() call was successful. - Server::new
-
Usage:
$obj = new Net::TCP::Server $service; $obj = new Net::TCP::Server $service, \%parameters; $obj = new Net::TCP::Server $lcladdr, $service, \%parameters;
Returns a newly-initialised object of the given class. This is much like the regular
new
method, except that it makes it easier to specify just a service name or port number, and it automatically does a setsockopt() call to setSO_REUSEADDR
to make the bind() more likely to succeed.Simple example for server setup:
$lh = new Net::TCP::Server 7788 or die; while ($sh = $lh->accept) { defined($pid=fork) or die "fork: $!\n"; if ($pid) { # parent doesn't need client fh $sh->stopio; next; } # child doesn't need listener fh $lh->stopio; # do per-connection stuff here exit; }
Note that signal-handling for the child processes is not included in this example. A sample server will be included in the final kit which will show how to manage the subprocesses.
Protected Methods
none.
Known Socket Options
These are the socket options known to the Net::TCP
module itself:
-
TCP_NODELAY, TCP_MAXSEG, TCP_RPTR2RXT
Known Object Parameters
There are no object parameters registered by the Net::TCP
module itself.
TIESCALAR
Tieing of scalars to a TCP handle is supported by inheritance from the TIESCALAR
method of Net::Gen
. That method only succeeds if a call to a new
method results in an object for which the isconnected
method returns true, which is why it is mentioned in connection with this module.
Example:
tie $x,Net::TCP,0,'finger' or die;
$x = "-s\n";
print $y while defined($y = $x);
untie $x;
This is an expensive re-implementation of finger -s on many machines.
Each assignment to the tied scalar is really a call to the put
method (via the STORE
method), and each read from the tied scalar is really a call to the getline
method (via the FETCH
method).
Exports
- default
-
none
- exportable
-
TCPOPT_EOL
,TCPOPT_MAXSEG
,TCPOPT_NOP
,TCPOPT_WINDOW
,TCP_MAXSEG
,TCP_MAXWIN
,TCP_MAX_WINSHIFT
,TCP_MSS
,TCP_NODELAY
,TCP_RPTR2RXT
,TH_ACK
,TH_FIN
,TH_PUSH
,TH_RST
,TH_SYN
,TH_URG
AUTHOR
Spider Boardman <spider@Orb.Nashua.NH.US>