TCP套接字通信的客户端和服务器之间的负时间跨度 [英] Negative time span between client and server for TCP socket communication

查看:53
本文介绍了TCP套接字通信的客户端和服务器之间的负时间跨度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

客户端和服务器之间用于TCP套接字通信的负时间跨度。



我尝试过:







我正在进行客户端和服务器TCP套接字通信,我通过发送一个字节格式的文件来计算上传速度客户端到服务器。我从客户端和服务器端获取发送时间(以UTC格式)我正在接收时间(以UTC格式)。当服务器和客户端保持相同的时间(包括秒)时,它工作正常。



但是当服务器滞后时间(几秒)而不是客户端时间时问题就出现了。因此,当我计算从客户端到服务器的文件包的遍历时间时,我得到负时间跨度。虽然我手动更改服务器时间,但它实际上需要时间。



也有一些客户机可能在他们的系统中错误地配置了他们的时间。



请提供解决此问题的最佳方法或解决方案。





感谢提前

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

推荐答案

简单:始终使用相同的时间源:通常是服务器。

从服务器获取时间你开始了,完成后再拿它。

一旦你开始使用不同的时间源,就会出现问题,因为PC时钟不是特别准确 - 它们不需要 - 因为它们经常从互联网来源纠正,默认情况下,Windows每周都会这样做一次。
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.


这篇关于TCP套接字通信的客户端和服务器之间的负时间跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆