Time client : Client « Network « Perl

Home
Perl
1.Array
2.CGI
3.Class
4.Data Type
5.Database
6.File
7.GUI
8.Hash
9.Language Basics
10.Network
11.Regular Expression
12.Report
13.Statement
14.String
15.Subroutine
16.System Functions
17.Win32
18.XML
Perl » Network » Client 
Time client
    

#!/usr/local/bin/perl
#Usage: timeclient [server_host_name]

$them = 'localhost';
$port = 9876 
$AF_INET = 2;
$SOCK_STREAM = 1;
$sockaddr = 'S n a4 x8';
($name, $aliases, $proto= getprotobyname('tcp');
($name,$aliases, $port, $proto)=getservbyname($port, 'tcp') unless $port =~ /^\d+$/;
($name,$aliases, $type, $len, $thataddr)=gethostbyname($them);
$that = pack($sockaddr, $AF_INET, $port, $thataddr);
if socket(SOCK, $AF_INET, $SOCK_STREAM, $proto ) ){
    print "Socket ok.\n";
}
else 
   die $!; 
}
if(connect(SOCK, $that)){
   print "Connect ok.\n";
}
else 
   die $!;
}
select(SOCK); $| = 1select (STDOUT);
$hertime = <SOCK>;
close(SOCK);
print "Server machine time is: $hertime\n";
@now = localtime($hertime);
print "\t$now[2]:$now[1] ", $now[4]+1,"/$now[3]/$now[5]\n";

   
    
    
    
  
Related examples in the same category
1.Two way client
2.The Client Program
3.The Client with Socket
4.A Daytime Client
5.Read the first line from a remote server
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.