TCP client using Socket module. : TCP « Network « Perl






TCP client using Socket module.

    

#!/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();  

   
    
    
    
  








Related examples in the same category

1.TCP client
2.TCP inet server
3.TCP server
4.tcp inet client
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.