As for the basic concept:
Simply send out a signal ( like a ping ) and wait till it returns. The execution time tells you the latency between server and client.
It is, however, something you need to do quite often to get an accurate value. The problem being that network latency is highly variable.
Then again, doing this might not be viable at all, since there is more involved than just sending and receiving the signal. For instance, the actual route a packet might take can vary.
Also, one would think that dividing the execution time by 2 results in an accurate result, but it does not.
Server to client might be faster than the return trip, screwing up the results.