#!/usr/bin/perl -w
#https://www.tutorialspoint.com/perl/perl_socket_programming.htm
#https://perldoc.perl.org/5.8.8/perlfaq5.pdf
#Script to Create a Client
#!/usr/bin/perl -w
# Filename : client.pl

use strict;
use Socket;
use IO::Handle;

# initialize host and port
my $host = shift || 'localhost';
my $port = shift || 7890;
my $server = "localhost";  # Host IP running the server

# create the socket, connect to the port
socket(SOCKET,PF_INET,SOCK_STREAM,(getprotobyname('tcp'))[2])
   or die "Can't create a socket $!\n";
connect( SOCKET, pack_sockaddr_in($port, inet_aton($server)))
   or die "Can't connect to port $port! \n";

my $line;
while ($line = <SOCKET>) {
   print "$line\n";
   print "\n---------------------------\n";
   print SOCKET "ack\n";
   flush SOCKET ;
   #sleep( 1 );
}



close SOCKET or die "close: $!";
#Now let's start our client at the command prompt, which will connect to the server and read message sent by the server and displays the same on the screen as follows −
#
#$perl client.pl
#Smile from the server
#NOTE − If you are giving the actual IP address in dot notation, then it is recommended to provide IP address in the same format in both client as well as server to avoid any confusion.
