perl实例代码,从服务器上读取数据,学习简单的socket编程。
代码:
#!/bin/perl
use Socket;
socket(SERVER, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
$addr = sockaddr_in(2336, inet_aton('server.com'));
connect(SERVER, $addr)
or die "连接服务器失败.n";
$line = <SERVER>;
print $line;
close(SERVER);