In the following snippet of code I am accepting a connection over $socket, which was created using IO::Socket::INET->new.
The problem that I am having with it is that it will not leave the while loop until the client terminates the connection.
($client) = $socket->accept();
my $read = "";
my $buffer;
print "DEBUG Point: 1\n";
while (read($client,$buffer,1024) > 0) {
print "DEBUG Point: 2\n";
$read .= $buffer;
}
print "DEBUG Point: 3\n";
print "$data \n";
The output from the above code is:
DEBUG Point: 1
DEBUG Point: 2
At this point it just sits and waits. Doesn't continue looping endlessly. If i terminate the connection from the client's end if then spits out the following:
DEBUG Point: 3
Test Data
If i send enough data through that it needs to loop several times to read it all, it will print the "DEBUG Point: 2" a couple times (as one would expect) and then just sits and wait until the client terminates the connection.
Any ideas what I might be doing wrong? Suggestions to fix it?
What's throwing me off is that it is not looping endlessly in the while statement, it seems to just sit at the read and wait.
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.