Daytime client, using symbolic host and service names : Socket « Network « Perl






Daytime client, using symbolic host and service names

    

#!/usr/bin/perl

use strict;
use Socket;

use constant DEFAULT_ADDR => 'your server';

my $packed_addr  = gethostbyname(shift || DEFAULT_ADDR) or die "Can't look up host: $!";
my $protocol     = getprotobyname('tcp');
my $port         = getservbyname('daytime','tcp') or die "Can't look up port: $!";
my $destination  = sockaddr_in($port,$packed_addr);

socket(SOCK,PF_INET,SOCK_STREAM,$protocol)  or die "Can't make socket: $!";
connect(SOCK,$destination)                  or die "Can't connect: $!";

print <SOCK>;

   
    
    
    
  








Related examples in the same category

1.Time Server with Socket
2.Using Socket to call a Perl CGI
3.Socket server
4.Perl Modules for Networking with Sockets
5.Open a socket
6.Post query to a CGI
7.Query a Perl CGI
8.Listen to a port
9.Using regular expresion to validate an IP address
10.Child handle and parent handle
11.Add a host, delete a host, add a user, delete a user, ping a host, list processes, list filesystems, lists hosts, and kill a process.
12.A Perl TCP server without the Socket module.
13.A Simple script to update your host/ip with dyndns.org service.