To determine if there is anything to read use select() (see IO::Select)
In reply to Re: Reading and writing sockets by gbarr in thread Reading and writing sockets by Marcello