Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

fin ack problems with IO::Socket

by djbiv (Scribe)
on Aug 22, 2003 at 02:28 UTC ( [id://285641]=perlquestion: print w/replies, xml ) Need Help??

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

Great Monks, I am stuck on a problem with the IO::Socket module and a simple piece of code. Here is the background... I am using a script to open 100 socket connections on one port, after I open the sockets I want to be able to close a few of them and open a few more, etc... running this on Active state 5.8 and 5.05... for AIX and neither the close or shutdown calls on the socket seem to be completely tearing the socket down? when I have closed down 5 sockets and run a netstat on my port the status is set to CLOSE_WAIT. a 'friend' w/ root access that ran an iptrace for me told me that my client isn't sending the final FIN ACK...? I looked in perldoc IO::Socket and perldoc Socket and didn't see any clues into the low level TCP protocal. Any ideas of where to go from here would be much appreciated!
my $count = 0; my @sock; while ($count < 100) { $sock[$count] = IO::Socket::INET->new(PeerAddr => $args{h}, PeerPort => $args{p}, Proto => 'tcp', Type => SOCK_STREAM, Timeout => 10); print "\nCONNECTED TO HOST:$args{h} PORT:$args{p} $count times \n" +; $count++; } sleep 10; my $count2; while ($count2 < 5) { shutdown ($sock[$count2], 2); print "Closed $sock[$count2]\n"; $count2++; } sleep 15; }

Replies are listed 'Best First'.
Re: fin ack problems with IO::Socket
by liz (Monsignor) on Aug 22, 2003 at 07:17 UTC
    I'm not very experienced in socket programming, so I'm on a limb here. Whenever I did do socket programming, I either always used close() on the socket when I was done, or just let the socket go out of scope (letting Perl handle all the intricacies automagically). In your case, the out of scoping could be done by changing this:
    shutdown ($sock[$count2], 2); print "Closed $sock[$count2]\n";
    to:
    print "Closed $sock[$count2]\n"; $sock[$count2] = undef;
    Hope this helps.

    Liz

      Thanks Liz, but no luck. I've tried these different ways to 'close' the socket connection but none of them seem to completely tear the connection down...
      shutdown ($sock[$count2], 2); # no more I/O at all shutdown ($sock[$count2], 1); # no more writing shutdown ($sock[$count2], 0); # no more reading close ($sock[$count2]);
Re: fin ack problems with IO::Socket
by tbone1 (Monsignor) on Aug 22, 2003 at 13:33 UTC
    This may sound goofy, but have you tried forcing a flush of the socket before you try to close it? I vaguely remember running into this problem once in some C code. Come to think of it, that code was running on an AIX box, too. Unfortunately, it was years ago, so the details are fuzzy, but the setup sounds similar.

    Also, I don't know if resetting $| will work on a socket as well as a filehandle, but I offer this suggestion for what it is worth. Sorry I can't be more definite or helpful.

    --
    tbone1
    Ain't enough 'O's in 'stoopid' to describe that guy.
    - Dave "the King" Wilson

      I seem to recall that newer versions of IO::Socket should have autoflush set automatically.

      -- vek --
Re: fin ack problems with IO::Socket
by djbiv (Scribe) on Aug 22, 2003 at 17:17 UTC
    UPDATE: OK, after more research I have come to find that it was a problem with the TCP/IP server, and the low level TCP/IP protocal on there side. Thanks everyone!
    ~Dan

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://285641]
Approved by ybiC
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-04-16 07:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found