Perl Two Way Client Communication
The below code written in Perl is used to create a two way client server network communication through the IO socket INET which is used for read and receive the information. The Peer Address, Peer Port Number, Protocol number and type of stream is used to set the two way client. Here in the below function the function fork is used to create the child process from the parent process; which will be the replica of the parent function and the only variation between these two is PID and PPID of the process
Perl Code to Two Way Client
use IO::Socket;
$socket = IO::Socket::INET->new
(
PeerAddr => 'server.com',
PeerPort => 1247,
Proto => "tcp",
Type => SOCK_STREAM
) or die "Could not create client.
";
unless (defined($child_pid = fork())) {die "Can not fork.
"};
if ($child_pid) {
while ($line = <>) {
print $socket $line;
}
} else {
while($line = <$socket>) {
print "Read this from server: $line";
}
}