#!/usr/bin/perl use IO::Socket; use strict; # 'Listen' parameter: this is the maximum number of connections that can be queued by the socket waiting for you to accept and process them # 'Reuse' option tells the system to allow reuse of the port after the program exits. This is to ensure that if our program exits abnormally and does not properly close the socket, running it again will allow opening a new socket on the same port. my $sock = new IO::Socket::INET ( LocalHost => '127.0.0.1', LocalPort => '6590', Proto => 'tcp', Listen => 1, Reuse => 1, ); die "Could not create socket: $!\n" unless $sock; while(1){ # To wait for a connection, we use the accept() method which will return a new socket through which we can communicate with the calling program. my $new_sock = $sock->accept(); print $sock->connected(); while(<$new_sock>) { print $_; #close($sock); } }