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

Hi,
I hope somebody can help me with this because I am stumped, what I am trying to do is open a tcp connection to a given port which a game uses, to see if the host is up or down.

This isn't the problem i'm having, the socket is opened, and I am able to detect the status just as I want, the problem is when I want to close the socket connection.

Here is my code to open the socket:

$socket = IO::Socket::INET->new(PeerAddr => $host, PeerPort => $port, Proto => "tcp", Type =>SOCK_STREAM, Timeout => "10") or die "game down\n\n";

And here is what I am using to close:

close($socket);

normally this would work.. however it has been determined that the game does not close it's connection unless it is sent a FIN bit. So if the game was to be open for 4 players and the probe was run 4 times nobody could join, and that is the smaller of the 2 problems, if the host is a Mac, and it is running OS 9 or older the entire computer goes down when they quit their game!

So basically where I am at is that I either need some method of running nmap using nmap -sS -p $port $host from perl, or of coding something that does the equivalent of it.

I apologize in advance if I did not provide enough information, any help would be greatly appreciated.

Thanks

Replies are listed 'Best First'.
(tye)Re: sockets question
by tye (Sage) on Jun 01, 2001 at 20:02 UTC

    I can image that some broken TCP/IP stacks don't handle close properly in all cases. Try using shutdown before close.

            - tye (but my friends call me "Tye")
Re: sockets question
by Anonymous Monk on Jun 01, 2001 at 16:45 UTC
    Normally close should send the FIN bit. There must be another reason.
Re: sockets question
by dl748 (Initiate) on Jun 02, 2001 at 02:51 UTC
    I've had some problems with what you are talking about. I've written many servers in perl. Some Prefork, Some Fork on command, some don't fork at all (yucky). Ok now when I was forking a process I was passing the socket off to the children for just reading and writing. The main parent didn't close the socket but i had the child close the socket. I server still had the socket open so it never got received so when the next socket connect came in it "overwrote" the variable and then terminated the connection. It never gets to send the close. This also depends on the type of OS you use also.