Hi
I wrote a socket server and client and tested on local host on my home system and I was able to communicate with multiple PC @ home. Now I moved the socket server to the web server and tried to test the client connection on my terminal. but every time i get a connection time out error message. I am posting the server code and client code here, can anyone help to find , what is going wrong....
Server
#!/usr/bin/perl
use strict;
use IO::Socket;
use POSIX 'WNOHANG';
use constant PORT => 12000;
my $quit = 0;
$SIG{CHLD} = sub {
while (waitpid(-1,WNOHANG)>0) {
}
};
my $lisen_socket = IO::Socket::INET->new(
LocalPort => PORT,
Proto => 'tcp',
Listen => 1,
Reuse => 1
);
die "cant create a soocket \n" unless $lisen_socket;
warn "server ready.. waiting for connection in port : 12000......\n";
while (!$quit) {
my $connection;
next unless $connection = $lisen_socket->accept;
defined(my $child = fork()) or die "cannot fork : $!\n";
if($child == 0) {
print "Inside child\n";
$lisen_socket->close();
&interact($connection);
exit 0;
print "exiting from child\n";
}
$connection->close();
}
sub interact {
my $data;
my $count = 0;
my $sock = shift;
#STDIN->fdopen($sock,"<") or die "cannot reopen STDIN : $!\n";
#STDOUT->fdopen($sock,">") or die "cannot reopen STDOUT : $!\n";
#STDERR->fdopen($sock,">") or die "cannot reopen STDERR : $!\n";
$| =1;
while(defined $sock) {
print $count;
$data = <$sock>;
if($data ne "") {
print "Server : $data\n";
print $sock "type next line\n";
$count++;
}
}
}
Client
#!/usr/bin/perl
use strict;
use IO::Socket::INET;
$| =1;
my $socket = IO::Socket::INET->new(
PeerHost =>'208.91.198.132',
PeerPort =>'12000',
Proto => 'tcp',
) or die "cannot create a socket $@\n";
print "TCP Connection Creatred Sucessfully\n";