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."
#!/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);
If any of you have any advice for this frustrated programmer please let me know.

dez

Edit by dws to add <readmore>

In reply to Help with socket reading and returning by basicdez

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.