简体   繁体   English

在TCP套接字数据发送C#之间获取恒定的延迟

[英]Getting constant delay between TCP Socket data send C#

I have a Client-Server application in C# 2010. In TCP Socket i setup Nodelay = True, and SendBufferSize = 0 for all the connected socket (client-Server) in my application. 我在C#2010中有一个客户端服务器应用程序。在TCP套接字中,我为应用程序中所有已连接的套接字(客户端服务器)设置了Nodelay = True,并且SendBufferSize = 0。

I am tracing every incoming-outgoing packets and writing that in logfile using streamwriter, which has autoflush property set true. 我正在跟踪每个传入的数据包,并使用具有自动刷新属性设置为true的streamwriter将其写入日志文件。

I noticed 1 thing that sometimes there is a constant delay (15-16ms) between 2 data packets while sending data. 我注意到一件事,有时在发送数据时两个数据包之间存在恒定的延迟(15-16毫秒)。 after few continuous sending this delay appears again. 连续发送几次后,此延迟再次出现。

Why this delay? 为什么要这样延误? and how can i avoid it.... 以及我该如何避免...

See the images... 看图片...

http://s4.postimg.org/uoly38shp/Trace_1.png http://s4.postimg.org/uoly38shp/Trace_1.png
http://s14.postimg.org/m4ab7oght/Trace_2.png http://s14.postimg.org/m4ab7oght/Trace_2.png

If you are using DateTime to track your performance 15ms is about the provided resolution. 如果您使用DateTime跟踪性能,则15ms就是所提供的分辨率。 Try using Stopwatch which is more reliable. 尝试使用更可靠的秒表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM