Listen to a port : Socket « Network « Perl






Listen to a port

    


use Socket;

socket(SERVER, PF_INET, SOCK_STREAM, getprotobyname('tcp'));

setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1);

$addr = sockaddr_in(2336, inet_aton('server.com'));

bind(SERVER, $addr) or die "Could not bind to port.\n";

listen(SERVER, SOMAXCONN) or die "Could not listen to port.\n";

while (accept(CLIENT, SERVER)) {
    print CLIENT "Hello from the server!\n";
}

close(SERVER);

   
    
    
    
  








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.Using regular expresion to validate an IP address
9.Child handle and parent handle
10.Daytime client, using symbolic host and service names
11.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.
12.A Perl TCP server without the Socket module.
13.A Simple script to update your host/ip with dyndns.org service.