A Perl TCP server without the Socket module. : Socket « Network « Perl






A Perl TCP server without the Socket module.

    


#!/usr/bin/perl -w

$PF_INET = 2;
$SOCK_STREAM = 1;

$port = 9999;

$pattern = 'S n C4 x8';

# Create an address using 0.0.0.0.
$this_addr = pack($pattern,$PF_INET, $port, 0,0,0,0);

$proto = getprotobyname("tcp");

socket(SERVER, $PF_INET, $SOCK_STREAM, $proto) or die "Can't create socket: $!";

bind(SERVER, $this_addr) or die "Can't bind: $!";

listen(SERVER,1) or die "Can't listen: $!";

print "Server listening on port $port\n";

for ( ; $paddr = accept(CLIENT,SERVER); close(CLIENT) ) {
    print CLIENT "Hello from server.\n";
}

   
    
    
    
  








Related examples in the same category

1.Time Server with Socket
2.Using Socket to call a Perl CGI
3.Socket server
4.Perl Modules for Networking with Sockets
5.Open a socket
6.Post query to a CGI
7.Query a Perl CGI
8.Listen to a port
9.Using regular expresion to validate an IP address
10.Child handle and parent handle
11.Daytime client, using symbolic host and service names
12.Add a host, delete a host, add a user, delete a user, ping a host, list processes, list filesystems, lists hosts, and kill a process.
13.A Simple script to update your host/ip with dyndns.org service.