2007fld has asked for the wisdom of the Perl Monks concerning the following question:

I'm using the script below to listen on a port on a server. Then there is a 2nd server probes this port. But the 2nd server got an error "tcp time out" due to my socket does not send FIN ack to finish the tcp connection. Any ideas?

use IO::Socket;
my $sock = new IO::Socket::INET (
LocalHost => '12.34.56.78',
LocalPort => '1350',
Proto => 'tcp',
Listen => 10,
Reuse => 1,
);
die "Could not create socket: $!\n" unless $sock;
listen ($sock, 3);
close($sock);

Replies are listed 'Best First'.
Re: IO::Socket does not send FIN ack?
by ikegami (Patriarch) on Jul 30, 2010 at 00:13 UTC

    You call listen twice (first with 10, then with 3). Get rid of the second listen.

    does not send FIN ack to finish the tcp connection.

    What connection? You never accept any connection, so no connections are created.

Re: IO::Socket does not send FIN ack?
by roboticus (Chancellor) on Jul 30, 2010 at 00:09 UTC

    2007fld:

    I've not done any socket programming for quite a few years, so this is a guess: But IIRC, it's because you haven't accepted a connection. Until you accept a connection, you don't have a connection with the remote server, and you won't get FIN until you terminate your connection.

    ...roboticus

      Thanks for the posts above. So if I change the second listen to accept, that should do work?
      If the accept works well, do I still need to explictly close the socket, or the socket will be closed automatically?
      How do I see monitor the sockets opened? I was using netstat -na |grep port#, but feel it is not very effective.
        The socket will be closed automatically when the all copies of it go out of scope or get overwritten.
Re: IO::Socket does not send FIN ack?
by morgon (Priest) on Jul 30, 2010 at 00:10 UTC
    You pass "Listen => 10" to your IO::Socket constructor, and then explicitely call listen($sock, 3).

    Does that make sense?

Re: IO::Socket does not send FIN ack?
by rowdog (Curate) on Jul 31, 2010 at 14:32 UTC
Re: IO::Socket does not send FIN ack?
by 2007fld (Acolyte) on Jul 30, 2010 at 20:15 UTC
    I tried just use the first "listen", but netstat won't show 1350 is listening on the 1st server. why? On the first server, what script or command can I use to see who(what IP) is trying to probe/connect, and whether the connection is a successful one. Thanks!