Example of a Perl TCP server using Socket module. : TCP « Network « Perl

Home
Perl
1.Array
2.CGI
3.Class
4.Data Type
5.Database
6.File
7.GUI
8.Hash
9.Language Basics
10.Network
11.Regular Expression
12.Report
13.Statement
14.String
15.Subroutine
16.System Functions
17.Win32
18.XML
Perl » Network » TCP 
Example of a Perl TCP server using Socket module.
    


#!/usr/bin/perl -w  
  
use IO::Socket;  
  
$port = 9999;  

$server_socket = IO::Socket::INET->new(
     LocalPort => $port,
     Listen    => SOMAXCONN,
     Proto     => 'tcp',
     Reuse     => 1)
     or die "Cannot open socket: $!";
         

print "Server listening on port $port\n";  
  
while $client_socket = $server_socket->accept() ) {
    $client_host = $client_socket->sockhost();
    print $client_socket "Hello from server.\n";
    print "Sent message to client on $client_host.\n";
    $client_socket->close();
}

   
    
    
    
  
Related examples in the same category
1.TCP client
2.TCP client using Socket module.
3.TCP inet server
4.TCP server
5.tcp inet client
6.Sample TCP client without the Socket module.
7.Sample TCP client.
8.Simple TCP Clients
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.