programming-examples/perl/Network/TCP client using Socket module.pl

26 lines
502 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
#!/usr/bin/perl -w
use IO::Socket;
$port = 999;
$num_args = scalar( @ARGV );
$host = 'localhost';
print "Connecting to $host\n";
$client_socket = IO::Socket::INET->new(
PeerPort => $port,
PeerAddr => $host,
Proto => 'tcp',
Type => SOCK_STREAM )
or die "Cannot open socket: $!";
# Read data from server.
$msg = <$client_socket>;
print "Recieved message from server:\n";
print "$msg\n";
$client_socket->close();