Tweak timeout period for socket connections on Win

2019-08-03 04:40发布

I'm testing how our software handles connection failures. We use socket.BeginConnect with a callback function set. The endpoint IP address and/or port number is deliberately invalid. The callback function gets called after ~21s every time (with timeout and connection failure, of course). I'd like to be able to tweak the timeout up or down for testing or final deployment.

According to this MSDN article for Windows CE 5.0, the key HKLM\Comm\Tcpip\Parms\TcpInitialRTT looks helpful. But I've tried the values 1, 2, 3 and 22 and the timeout does not change from ~21s. The computer was rebooted after each change.

Can the timeout for TCP/IP socket connections be tweaked at OS level? Using C# and .NET Compact Framework.

1条回答
我只想做你的唯一
2楼-- · 2019-08-03 04:58

You must do so using

IAsyncResult result = mysocket.BeginConnect(...)

then wait on the

result.AsyncWaitHandle.WaitOne(yourtimeouthere, false);
查看更多
登录 后发表回答