2

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?

7
  • 2
    Always use use warnings and use strict in your code. Commented Feb 13, 2015 at 10:10
  • 1
    when I use use strict, I get errors for variable initialization and script is stopped Commented Feb 13, 2015 at 10:28
  • 1
    First declare all your variables. Commented Feb 13, 2015 at 10:36
  • the same script was running successfully in Windows 7 ultimate machine. Im facing issue in Windows 7 enterprise.So I think use strict would not be a problem. Commented Feb 13, 2015 at 10:45
  • my $sock = IO::Socket::INET->new(...) or die $!. The $! will tell you what's wrong Commented Feb 13, 2015 at 14:46

1 Answer 1

1

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.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.