tcp inet client : TCP « Network « Perl






tcp inet client

    

#!/usr/bin/perl 

use warnings;
use strict;

use Socket;

my $proto = getprotobyname('tcp');
my $host = inet_aton('localhost');
my $port = 4444;

my $servaddr = sockaddr_in($port, $host);

socket SERVER, PF_INET, SOCK_STREAM, $proto or die "Unable to create socket: $!";

connect SERVER, $servaddr or die "Unable to connect: $!";

select SERVER; $| = 1; select STDOUT;

print "Client connected.\n";
print "Server says: ", scalar(<SERVER>);
print SERVER "Hello from the client!\n";
print "Server says: ", scalar(<SERVER>);
print SERVER "And goodbye!\n";
print "Server says: ", scalar(<SERVER>);
close SERVER;

   
    
    
    
  








Related examples in the same category

1.TCP client
2.TCP client using Socket module.
3.TCP inet server
4.TCP server
5.Sample TCP client without the Socket module.
6.Sample TCP client.
7.Simple TCP Clients
8.Example of a Perl TCP server using Socket module.