IO :: Socket :: INET返回一个空套接字

时间:2015-02-13 09:51:26

标签: ios perl sockets

这是我的代码:

 my $server_socket = new IO::Socket::INET
            (
                LocalPort => 8378,
                Type      => SOCK_STREAM,
                Listen    => $SOMAXCONN,
                Proto     => 'tcp',
                Reuse     => 1
            ) || die "$!\n";

        $serverName   = $ENV{COMPUTERNAME};
        $socketPortNr = 8378;
        $clientSocket = new IO::Socket::INET (PeerAddr => $serverName,
                                                  PeerPort => $socketPortNr,
                                                  Proto    => 'tcp');

$clientSocket为空。

$clientSocket的原因是什么?

1 个答案:

答案 0 :(得分:1)

没有必要推测。如其文档中的示例所示,IO::Socket::INET->new在失败时在$@中放置了错误消息。

my $client_socket = new IO::Socket::INET->new(
   ...
)
   or die("Can't create client socket: $@\n");

$!也已设置,但它提供的信息并不总是那么精确。)