You do not need to use synchronous communication (i.e. send a packet, block and wait for the results), especially if you use UDP. Just ask one thread to send pings, and the other - the constant reception of pongs in one socket. If you need to perform complex processing with the results, you can use another for this.
The problem will be in the sending logic - you do not want to suppress your own Internet connection, so I would suggest a custom packet rate. In addition, UDP packets can be lost on the network, so retry sending at least once or twice before giving up. I would suggest about 2 seconds as a timeout, because if the ping to game server (i.e. with high latency) takes longer, it probably will not be used anyway.
source share