#!/usr/bin/perl -w use Socket; # For constants like AF_INET and SOCK_STREAM $proto = getprotobyname('tcp'); #get the tcp protocol my($sock); socket($sock, AF_INET, SOCK_STREAM, $proto) or die "could not create socket : $!"; my $remote = $ARGV[0]; my $port = $ARGV[1]; $iaddr = inet_aton($remote) or die "Unable to resolve hostname : $remote"; $paddr = sockaddr_in($port, $iaddr); #socket address structure connect($sock , $paddr) or die "connect failed : $!"; print "Connected to $remote on port $port\n"; print "Waiting for approval from $remote ...\n"; my $approved = <$sock>; if ($approved eq 'yes') { print "Welcome, you were approved by $remote\n"; while () { my $input = ; send($sock , "I am a client!" , 0) or die "sendo failed : $!"; if ($input eq 'end_chat') { close($sock); exit(0); } } send($sock , "I am a client!" , 0) or die "sendo failed : $!"; while ($line = <$sock>) { print $line; } } else { print "Sorry, you were rejected by $remote\n"; close($sock); exit(0); } exit(0);