in reply to variable timeout
You should consider leaving the default value of the socket timeout. Usually, it is best left alone unless you expect an extremely poor network connection. If you really need it, look at the SO_LINGER socket option. The initial receipt time (RTT-round trip time) of the packet in no way determines the RTT of the rest of the packets. Of course, if you insist on setting this, it is as simple as setting the SO_RCVTIMEO. Look at setsockopt.