use IO::Socket; use strict; use warnings; our $F_PORT = shift or die "Please specify First port number\n"; our $T_PORT = shift or die "Please specify Third port number\n"; #our $file = shift or die "Please specify input file\n";; my $f_socket = IO::Socket::INET->new('LocalPort' => $F_PORT, 'Proto' => 'tcp', 'Listen' => 2) or die "Second: Can't create socket to First($!)\n"; my $t_socket = IO::Socket::INET->new( 'PeerAddr' => "localhost", 'PeerPort' => $T_PORT, 'Proto' => 'tcp') or die "Second: Can't create socket to Third($!)\n"; my $match = "brenna"; print "Second listening\n"; while(my $first = $f_socket->accept()) { #setup acknowledgement print "Second: Accepted connection from First..\n"; my $f_host = gethostbyaddr($first->peeraddr, AF_INET); my $f_port = $first->peerport; while (<$first>) { my $name = $_; chomp($name); #send acknowledgement message to First print "Received from [$f_host $f_port]: $name\n"; #print $f_socket "$.: $name\n"; if($name eq $match) { print "Second found match: $name\n"; print "Second sending \"$name\" to Third\n"; print $t_socket "$match\n"; while(<$t_socket>) { #print "Second has accepted socket to Third...\n"; my $name = $_; chomp($name); my $t_host = gethostbyaddr($t_socket->peeraddr, AF_INE +T); my $t_port = $t_socket->peerport; print "Received from [$f_host $f_port]: $name\n"; } } } } die "Second: Can't accept socket from First($!)\n";
Any help would be much much appreciated... I've been beating my head against this for days now.
In reply to Re^5: Bidirectional use of a Socket
by scotchfx
in thread Bidirectional use of a Socket
by scotchfx
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |