GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  NET::TCP::SERVER (3)

.ds Aq ’

NAME

Net::TCP::Server - TCP sockets interface module for listeners and servers

CONTENTS

SYNOPSIS



    use Net::Gen;               # optional
    use Net::Inet;              # optional
    use Net::TCP;               # optional
    use Net::TCP::Server;



DESCRIPTION

The Net::TCP::Server module provides services for TCP communications over sockets. It is layered atop the Net::TCP, Net::Inet, and Net::Gen modules, which are part of the same distribution.

    Public Methods

The following methods are provided by the Net::TCP::Server module itself, rather than just being inherited from Net::TCP, Net::Inet, or Net::Gen.
new Usage:



    $obj = new Net::TCP::Server;
    $obj = new Net::TCP::Server $service;
    $obj = new Net::TCP::Server $service, \%parameters;
    $obj = new Net::TCP::Server $lcladdr, $service, \%parameters;
    $obj = Net::TCP::Server->new();
    $obj = Net::TCP::Server->new($service);
    $obj = Net::TCP::Server->new($service, \%parameters);
    $obj = Net::TCP::Server->new($lcladdr, $service, \%parameters);



Returns a newly-initialised object of the given class. This is much like the regular new method of the other modules in this distribution, except that it makes it easier to specify just a service name or port number, and it automatically does a setsockopt() call to set SO_REUSEADDR to make the bind() more likely to succeed. The SO_REUSEADDR is really done in a base class, but it’s enabled by defaulting the reuseaddr object parameter to 1 in this constructor.

The examples above show the indirect object syntax which many prefer, as well as the guaranteed-to-be-safe static method call. There are occasional problems with the indirect object syntax, which tend to be rather obscure when encountered. See http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1998-01/msg01674.html for details.

Simple example for server setup:



    $lh = Net::TCP::Server->new(7788) or die;
    while ($sh = $lh->accept) {
        defined($pid=fork) or die "fork: $!\n";
        if ($pid) {             # parent doesnt need client fh
            $sh->stopio;
            next;
        }
        # child doesnt 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. See Internet TCP Clients and Servers in perlipc for related examples which manage subprocesses. However, on many operating systems, a simple $SIG{CHLD} = IGNORE; will prevent the server process from collecting ‘zombie’ subprocesses.

    Protected Methods

none.

    Known Socket Options

There are no socket options specific to the Net::TCP::Server module.

    Known Object Parameters

There are no object parameters registered by the Net::TCP::Server module itself.

    Exports

default none
exportable none
tags none

THREADING STATUS

This module has been tested with threaded perls, and should be as thread-safe as perl itself. (As of 5.005_03 and 5.005_57, that’s not all that safe just yet.) It also works with interpreter-based threads (’ithreads’) in more recent perl releases.

SEE ALSO

Net::TCP(3), Net::Inet(3), Net::Gen(3)

AUTHOR

Spider Boardman <spidb@cpan.org>
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 NET::TCP::SERVER (3) 2016-03-17

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.