I have no real way to determine when the data is finished being read, other than there is nothing else coming in. Basically, I want to read the data from the client, act on it and return the results to the client and then have the server terminate the connection. (Using sysread in this example, because according to "Network Programming with Perl, page 359" it is the safest option with a nonblocking socket)
I've modified the code in the following way:
($client, my $client_addr) = $server->accept( );
my $result = fcntl($client, F_SETFL, O_NONBLOCK);
my $read = "";
my $buffer;
print "DEBUG Point: 1\n";
while (sysread($client,$buffer,1024)) {
print "DEBUG Point: 2\n";
$read .= $buffer;
}
print "DEBUG Point: 3\n";
print "$read\n";
This is a step closer. It exits the loop and prints the data ($read) to the terminal window.
Problem is, i am no longer seeing all of the data. With the original code from the first post I saw all of the data. The only problem was that it was not leaving the while loop after reading all of the data in. Now it seems to be leaving off the last few lines (i'm sending 14 lines of text through and only seeing 9 being printed to the terminal)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.