I only need to say why if I send a message terminated by a
new-line the server read the message , without the new-line
I got no answer.
If the server is something like this :
while( 1 )
{
my $new_sock = $sock->accept();
$stmp = <$new_sock>;
print "$stmp";
print $new_sock "$stmp\n";
close($new_sock);
}
close($sock);
the server hang waiting for a newline.
what cha I do to avoid the server waiting for the newline.
| [reply] |
You cannot use <$new_sock> anymore, because that waits for a newline character. You need to use read instead. You also likely want nonblocking IO using the four-argument version of select. Likely, IO::Select wraps this up nicely for you. There is example code on how to use IO::Select in its documentation. For select, I didn't find any nice documentation.
Basically, select and IO::Select return once a socket is ready to receive more data or to send more data, and tell you which socket(s).
There are three multiplexing frameworks I know of that handle nonblocking sockets in a manner that is more or less inconveniencing - POE, Danga::Socket and Coro. All three have different uses and different shortcomings.
| [reply] [d/l] [select] |
read is not ok, because is mapped on fread
instead I used sysread.
I replaced the statemente :$sres = <$new_sock>;
with the following code:
(mybe it should be helpfull to someone else )
$rin="";
$sres = "";
vec($rin,fileno($new_sock),1) = 1;
$nfound=select( $rin, undef, undef, .1 );
while ( $nfound )
{
sysread( $new_sock, $c, 1 );
chomp $c;
$sres .= $c;
$nfound=select( $rin, undef, undef, .1 );
}
| [reply] |