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

All i have the following socket code.

my $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $serverport, Listen => SOMAXCONN, Reuse => 1); die "can't setup server" unless $server; &writelog("$date: INFO: Server $0 started accepting clients <br>connec +tions"); while ($client = $server->accept()) { $client->autoflush(1); my $hostinfo = gethostbyaddr($client->peeraddr); my $remoteclient = $hostinfo->name; &writelog("$date: INFO: New client connection from <br> $remoteclie +nt"); while ( <$client>) { next unless /\S/; # blank line

Now when run this on my suse 9.1 kernel Linux 2.6.4-52-default
i get no issues i can telnet to the port and works fine.
when i run this on my 2.6.5-7.193-smp
I telnet localhost the port 9000 and connects i exit, perfect
when i try and telnet from another machine ie windows to the socket it connects then the program exits and stop running
. This does not happen on my first machine.
Is there a debug i can use.

20051012 Janitored by Corion: Added code tags, formatting

2005-10-12 Retitled by Arunbear; s/Sock/Socket/

Replies are listed 'Best First'.
Re: Sock connection killing program
by sgifford (Prior) on Oct 12, 2005 at 21:05 UTC
    Try adding more error checking. Maybe gethostbyaddr is failing, and so the next line tries to dereference an undefined reference, for example.

    Also, note that your script won't accept a second connection while the first is still running; it won't get back to the accept line until it's done reading from $client.

Re: Socket connection killing program
by doctor_moron (Scribe) on Oct 13, 2005 at 03:11 UTC
    Looks you ignore close(socket filehandle), i mean like this :

    sock($server);
    sorry..typos
    close $server;

    Have a look at code below :

    use strict; use IO::Socket qw(:DEFAULT :crlf); $/ = CRLF; my $port = 20000; my $false = 0; my $sock = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $port, Listen => SOMAXCONN, Reuse => 1) or die "can't create socket $! \n"; warn "Waiting for Incoming connection on $port \n"; while(!$false) { next unless my $session = $sock->accept; my $client = gethostbyaddr($session->peeraddr,AF_INET) || $session-> +peerhost; my $port = $session->peerport; warn "Connection from [$client, $port]\n"; while(<$session>) { chomp; print $session "you typed $_ \n" ; } warn "Connection from [$client, $port] finished \n"; close $session } close $sock;
Re: Socket connection killing program
by talexb (Chancellor) on Oct 12, 2005 at 18:40 UTC

    Is there anything in the messages file (/var/log/messages)?

    For debugging, I highly recommend Log::Log4perl.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Re: Socket connection killing program
by 5mi11er (Deacon) on Oct 12, 2005 at 18:57 UTC
    Have you checked if the windoze firewall is affecting you?