perl实例分享:简单的时间服务器的例子。
代码:
#!/usr/bin/perl -T
#Usage: timeserver [port number]
use strict;
use warnings;
$port=9876;
$AF_INET=2;
$SOCK_STREAM = 1;
$sockaddr = 'S n a4 x8';
($name,$aliases,$proto)=getprotobyname('tcp');
if($port !~ /^d+$/){
($name, $aliases, $port)=getservbyport($port,'tcp');
}
print "Port = $portn";
$this = pack($sockaddr, $AF_INET, $port, "