L
Lim kiang Leng
I am new to try up the socket programming, I try to set up a socket in
my company but seem like it failed. Althught , it know the present of
the server, but seem like they cant talk. Below is my server and
client's program. Is any one know why i failed to communicate?
########
#server#
########
print "prgram is in running ... \n" ;
use IO::Socket;
my $sock = new IO::Socket::INET (
LocalHost => 'machine.mycompany.com',
LocalPort => '7000',
Proto => 'tcp',
Listen => 1,
Reuse => 1,
);
die "Could not create socket: $!\n" unless $sock;
my $new_sock = $sock->accept();
print "$_" ;
while(defined(<$new_sock>)) {
print $_;
}
close($sock);
########
#client#
########
use IO::Socket;
print "programming " ;
my $sock = new IO::Socket::INET (
PeerAddr =>
'machine.mycompany.com',
PeerPort => '7000',
Proto => 'tcp',
);
die "Could not create socket: $!\n" unless $sock;
print $sock "Hello there!\n";
close($sock);
my company but seem like it failed. Althught , it know the present of
the server, but seem like they cant talk. Below is my server and
client's program. Is any one know why i failed to communicate?
########
#server#
########
print "prgram is in running ... \n" ;
use IO::Socket;
my $sock = new IO::Socket::INET (
LocalHost => 'machine.mycompany.com',
LocalPort => '7000',
Proto => 'tcp',
Listen => 1,
Reuse => 1,
);
die "Could not create socket: $!\n" unless $sock;
my $new_sock = $sock->accept();
print "$_" ;
while(defined(<$new_sock>)) {
print $_;
}
close($sock);
########
#client#
########
use IO::Socket;
print "programming " ;
my $sock = new IO::Socket::INET (
PeerAddr =>
'machine.mycompany.com',
PeerPort => '7000',
Proto => 'tcp',
);
die "Could not create socket: $!\n" unless $sock;
print $sock "Hello there!\n";
close($sock);