user2338040
user2338040

Reputation: 101

IO::Socket::INET returns a empty socket

This is my code:

 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');

but the $clientSocket is empty.

What could be the reason for empty $clientSocket?

Upvotes: 2

Views: 472

Answers (1)

ikegami
ikegami

Reputation: 385789

There's no need to speculate. As shown in the examples in its documentation, IO::Socket::INET->new places an error message in $@ when it fails.

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

($! is also set, though the information it provides is not always as precise.)

Upvotes: 1

Related Questions