basicdez has asked for the wisdom of the Perl Monks concerning the following question:
This is the code I am currently using to read from a socket (that piece is working) and then I want to return a message to the same socket (I cannot seem to get this to work). If any of you would have the time to look this over and give me some advice, that would be awesome. I am also getting an error from the code that is telling me that states
"Use of uninitialized value at /develop/release/cmsidev/dev/cr/cds/comms/x2p/pd2x line 130, < +FILE1> chunk 1 (#2) (W) An undefined value was used as if it were already defined. It + was interpreted as a "" or a 0, but maybe it was a mistake. To suppre +ss this warning assign an initial value to your variables."
If any of you have any advice for this frustrated programmer please let me know.#!/usr/bin/perl -w BEGIN { $CHANGEVAR = $ENV{CRROOTWSDIR}; if ($CHANGEVAR =~ /^([-\/\w.]+)$/) { $MAINPATH = $1; } else { die "Invalid path, please check setenv"; } $LIB = "$MAINPATH/cr/cds/comms/x2p"; } use lib "$LIB"; my $runpath = "$ENV{CRROOTWSDIR}/cr/cds/comms/x2p"; use diagnostics; use strict; use sigtrap; use IO::Select; use IO::Socket::INET; use X2PCONF; $SIG{CHLD} = 'IGNORE'; ### Kill zombie processes immediately. $SIG{PIPE} = 'IGNORE'; ### Ignore RST (reset flag) if there's an + error writing to socket. $| = 1; ### Enable Autoflushing of I/O. { my $sock = new IO::Socket::INET ( LocalAddr => $X2PCONF::cdsd_host, LocalPort => $X2PCONF::pd2x_port, Proto => 'tcp', Listen => 5, Reuse => 1, ); die "Could not create socket\n" unless $sock; my $sock_new; my $buffer; CONNECTION: while ($sock_new = $sock->accept()) { if ((my $chldpid = fork ()) != 0) { close ($sock_new); next CONNECTION; } my $buf = ' '; while (defined ($buf = <$sock_new>)) { if ($buf eq "\"ZZZ\"\n") { $buffer .= "\"EOS\""; last; } else { $buffer .= $buf; } } last; } print " $buffer \n"; open(DATA, ">$runpath/pd2x.dat") or die ("error opening pd2x.dat $ +!\n"); print DATA $buffer; print "$runpath/pd2x.dat \n"; system ("perl $runpath/packets2a.pl"); my $message; my $fname_response = "$runpath/response.dat"; my $check_value = ' '; open FILE1, "< $fname_response" or die "Cannot open datfile: ", $!; while (<FILE1>) { $check_value = $_; if ($check_value ne "END") { $message = ($message . $check_value); } else { next; } } close (FILE1); print $sock ($message); print "Response packet $message \n"; close ($sock); } exit (0);
dez
Edit by dws to add <readmore>
|
---|
Replies are listed 'Best First'. | |
---|---|
•Re: Help with socket reading and returning
by merlyn (Sage) on Mar 14, 2002 at 14:24 UTC | |
Re: Help with socket reading and returning
by Caillte (Friar) on Mar 14, 2002 at 14:36 UTC |
Back to
Seekers of Perl Wisdom