Click here to Skip to main content
15,894,955 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Negative time span between Client and Server for TCP Socket communication.

What I have tried:

Hi

I am having Client and Server TCP socket communication for which i am calculating Upload speed by sending a file in byte format from Client to Server. I am taking the Send time(in UTC format) from Client and from Server side I am taking Receive time(in UTC format). It works fine when both Server and client maintain same time (including seconds).

But the problem comes when the Server is lagging time(few seconds) than Client time. Hence I am getting negative time span when I calculate the Traverse time of the file packet from Client to Server. Though i manually change the Server time it takes its actually time back.

Also few client machines may have their time wrongly configured in their system.

Please provide the best approach or solution to resolve this issue.


Thanks in Advance
Posted
Updated 1-Aug-16 2:38am
v2

1 solution

Simple: always use the same time source: normally the server.
Get the time from the server when you start, get it again when you finish.
As soon as you start using separate time sources you will get problems as PC clocks aren't particularly accurate - they don't need to be - as they are often "corrected" from an internet source and by default Windows does this once a week.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900