How can I read from an IO::Socket::INET filehandle only if there is a complete line?

When reading from a IO::Socket::INET filehandle it can not be assumed that there will always be data available on the stream. What techniques are available to either peek at the stream to check if data is available or when doing the read take no data without a valid line termination and immediately pass through the read?

Answers


Set the Blocking option to 0 when creating the socket:

$sock = IO::Socket::INET->new(Blocking => 0, ...);

Checkout IO::Select; it's very often what I end up using when handling sockets in a non-blocking way.


Need Your Help

how does server find out my ipaddress behind a router?

java sockets udp

I have a question regarding how server can send udp packet to my laptop successfully when my laptop is behind a router and the server is using my external ip address. I was trying out udp client and

How do you rate Oracle Portals as a platform?

oracle oracleportal

A client has asked whether or not I can provide some support for his intranet which runs on Oracle Application Server Portal. Not having used this technology before I thought I'd ask if anyone else...