In my opinion the most flexible socket option to control your program is using the select API, which allows you to wait for the socket and specify a timeout (you can also issue a non-blocked receive, but it is, in my opinion, the wrong approach).
This page describes the select API very well. It discuss mainly the server, but you can also use it on your client with no problem.
Dig Deeper on Physical connections to iSeries
Related Q&A from Shahar Mor
Use work station customize object or printer type in iSeries Access to print the output of an RPG file from the AS/400 to an HP printer. Continue Reading
On the AS/400 library, source files are multi-member. View source files using GET QCLSRC.membername or MGET QRPGSRC.* Continue Reading
Connecting the iSeries in AS/400, issue STRHOSTSVR *ALL. Make sure the as-signon port is in listen state and check the firewall settings. Continue Reading