Loading ...
Sorry, an error occurred while loading the content.

Perl Sockets

Expand Messages
  • Ben Maynard
    I was hoping someone could help with this code I have? I have a socket being opened for a continuous stream from a single connection, however, for some reason
    Message 1 of 1 , Oct 12, 2000
    • 0 Attachment
      I was hoping someone could help with this code I have?

      I have a socket being opened for a continuous stream from a
      single connection, however, for some reason after I have
      recieved just 2 bits of data, the socket stops recieving, and
      closes, can anyone offer advice, I have added forking hoping
      this would fix the problem, and it did make a slight improvement
      as before it was only taking one piece of data.
      This is the code:
      sub connect_port {
      $local = IO::Socket::INET->new(Type=> SOCK_STREAM,
      Proto=>"tcp",
      LocalPort=>$sck,
      Listen=>1,
      Reuse=>1)
      || die dienice();

      open(PRO, "> pid.dat") || die print "Cannot print process: $!";
      print PRO getppid();
      close(PRO);

      while ($remote = $local->accept()) {

      $remote->autoflush(1);

      FORK: {

      my $kid = fork;
      if (defined($kid)) {
      my $nread = sysread($remote, $inp, 100000024);
      chomp($inp); # Remove trailing \n from $inp
      if ($inp=~ /901/) { # If $inp is "901" terminate program
      close($local);
      print "*** Terminate Signal Recieved exiting....(exit(1))";
      unlink <pid.dat>;
      $dbh->disconnect();
      exit();
      } else {
      print "*** $inp\n"; # Else print to screen and datasource
      database_connect();
      }
      }
      elsif ($! =~ /No more process/) {
      sleep 5;
      redo FORK;
      } else {
      print "Failed!"
      }
      }
      }
      connect_port($sck, $datasource, $datasource2);
      }


      Looking at this can anyone hazard a guess as to why it closes and stops
      recieving.
      TIA
      Ben
    Your message has been successfully submitted and would be delivered to recipients shortly.