Perl 的 Socket 客户端获取服务器时间

2015-12-14 0 491
Perl 的 Socket 客户端获取服务器时间
#!/usr/local/bin/perl -Tw
require 5.6.0;
use Socket;
use FileHandle;
use strict;
my($remote, $port, @thataddr, $that,$them, $proto,@now,$hertime);

print "client\n";
$remote = shift || 'localhost' ;
$port = 99999 ;  # timeserver is at this port number
@thataddr=gethostbyname($remote);

$that = pack('Sna4x8', AF_INET, $port, $thataddr[4]);

$proto = getprotobyname('tcp');
if ( socket(SOCK, PF_INET, SOCK_STREAM, $proto ) ){
     print "Socket ok.\n";
}
else { 
     die $!; 
}
if (connect(SOCK, $that)) {
     print "Connect ok.\n";
}
else {
     die $!;
}
SOCK->autoflush;
$hertime = <SOCK>;
close(SOCK);
print "Server machine time is: $hertime\n";
@now = localtime($hertime);
print "\tTime-$now[2]:$now[1] ","Date-",$now[4]+1,"/$now[3]/$now[5]\n";

遇见资源网 perl Perl 的 Socket 客户端获取服务器时间 http://www.ox520.com/13288.html

上一篇:

已经没有上一篇了!

下一篇:

已经没有下一篇了!

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务