Just a wild guess here. I notice that your code is executed within eval block. However, you do not check for its status, which means that you silence any errors and/or exceptions. Try to check for $@ in your last statement.
Also, depending on the socket option, i.e. if your socket is nonblocking, you should check for EAGAIN system error to see if the socket is ready to be read. Better yet use select or its OO counterpart IO::Select to determine if socket is readable.
Update: Fixed mixup between $! and $@, pointed out by ikegami
use IO::Select; my $sock_read_hdl = IO::Select->new(); $sock_read_hdl->add($oSocket); # Block here until message arrives my ($read_ready) = IO::Select->select($sock_read_hdl, undef, undef, un +def); # Now we are ready to read message. Note: $read_ready->[0] == $oSocket + here. eval { ... } or die $@; # As pointed out by ikegami, thanks.
I usually use a function instead of eval block and return an array containing message, byte count and possible error. Such as in
sub read_msg { my ($sock, $bcount, $buf, $msg) = (shift, 0, '', ''); # Use sysread for stream-oriented sockets READ_MSG: while (my $bytes_read = sysread($sock, $buf, 1024)) { # Handle partial read $bcount += $bytes_read; $msg .= $buf; } # Just in case redo READ_MSG if $! =~ /Resource temporarily unavailable/; # All other errors trigger unconditional return with error return ($msg, $bcount, $!) if ($!); # Return success return ($msg, $bcount, ''); }
So now our message reading routine looks like ...
... # Instead of eval block use our new function call my ($msg, $bcount, $error) = read_msg($read_ready->[0]); # Check for errors and empty messages die $error, "\n" if ($error); die "Nothing received!\n" if ($bcount == 0); ...
Hope this helps with your problem here. BR
In reply to Re: No data received on client socket
by caelifer
in thread No data received on client socket
by rbi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |