Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Greetings to all monks.

Please help me with this dilemma if you can. I am reading in a data stream through a socket and would like to read in the data stream beginning with "FOO" and ending with "END". I can read this in one line at a time, which works out perfectly for me, but I cannot get the reading in through this socket to stop when this hits END. What is happening is that I can see it reading in END, but the socket never closes and the listener continues to listen for more data through the socket. If you have any wisdom in this area I would appreciate your help.

Here is the data file.
"FOO" "localhost" "pd2x" "GOO" "Internal" "External" "Abbreviated" 00 50000 0 "ICK" "REQUEST" 0 "Yes" "No" "Absolutely" "END"
And here is the code I am using to read it in.
#!/usr/bin/perl -w # server use strict 'refs'; use strict 'subs'; use diagnostics; use strict; use sigtrap; use IO::Select; use IO::Socket::INET; $| = 1; ### Enable Autoflushing of I/O. my $sock = new IO::Socket::INET ( LocalAddr => localhost, LocalPort => 1000, Proto => 'tcp', Listen => 5, Reuse => 1, ); die "Could not create socket\n" unless $sock; my $buf = ' '; my $buffer = ' '; my $new_sock; while ($new_sock = $sock->accept()) { while (defined ($buf = <$new_sock>)) { if ($buf eq "\"END\"") { close ($sock); } else { print $buf; $buffer .= $buf; } } } print "$buffer \n";

peace, LOVE and ((code))


In reply to Reading an incoming Data Stream.. by basicdez

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (1)
As of 2022-07-01 17:15 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (99 votes). Check out past polls.