in reply to while(select())

You can check this thread. I've posted a complete function there that reads messages from socket. Maybe that's what you are looking for.

BR