Q: Read from a socket for n seconds I'd like to put a timeout reading a socket, i found this in C++ and i'd like to convert it on Java.
int readable_timeo(SOCKET fd, int sec){
fd_set rset;
struct timeval tv;


FD_ZERO(&rset);
FD_SET(fd, &rset);

tv.tv_sec = sec;
tv.tv_usec = 500000;

return (select(0, &rset, NULL, NULL, &tv));}

Any suggestion?
Thanks for the help!

A: The simple equivalent in Java is Socket.setSoTimeout(). The equivalent of the code you posted, which isn't the simplest, is Selector.select().
