C#设置接收超时(最佳/足够时间)

问题描述 投票:-2回答:1

我想知道什么是接收/发送超时的最佳时间

tcpSocket.ExclusiveAddressUse = true;
tcpSocket.LingerState = new LingerOption (true, 10);
tcpSocket.NoDelay = true;
tcpSocket.ReceiveTimeout = 5000;
tcpSocket.SendTimeout = 5000;
tcpSocket.Ttl = 42;
Console.WriteLine("Tcp Socket configured:");

我正在使用5秒,但我感觉它很高..在.net示例中它们设置为1秒

c# .net tcp websocket
1个回答
1
投票

根据msdn,超时定义如下:

Receive Timeout :Gets or sets the interval of time that a connection can remain inactive, during which no application messages are received, before it is dropped.
Send Timeout : Gets or sets the interval of time provided for a write operation to complete before the transport raises an exception.

我会将接收超时保留为默认值(无限),因此当您有空闲通道时,连接将不会关闭。除非你有keep-alive运行,它定期发送一个零字节的消息。

发送超时你必须小心设置值太低。 TCP是可靠的意味着每个数据报获得一个ack。当没有发送确认时,另一个数据报通常最多发送3次。

当通道缓慢重试开始发生时,TCP会发生什么情况,发送额外的重复数据报,然后更频繁地减慢通道速度,直到有太多重试没有数据通过。

此外,当连接的接收端运行缓慢时,ack可能不会立即返回。所以你必须允许接收结束时间发出确认。通常,ack由网卡自动完成,不应该是一个问题。

此外,您还必须考虑是否有拦截邮件的病毒检查程序或防火墙。

© www.soinside.com 2019 - 2024. All rights reserved.