Linux上的套接字连接超时

时间:2019-07-15 14:11:20

标签: c# linux .net-core

我有一个示例应用程序试图与不存在的IP地址和端口连接:

var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
    socket.Connect("10.1.2.3", 22);
}
catch (Exception e)
{
    Console.WriteLine(e.Message);
}
finally
{
    socket.Dispose();
}

当我在Windows上运行此代码时,我在21秒内收到错误消息:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 10.1.2.3:22

但是当我在linux上运行相同的代码时,我等待2分10秒才能得到相同的错误。 linux是否有任何特定设置可以减少此超时?我已经尝试过减少tcp_retries 1和tcp_retries2(Change the TCP timeout for a linux network device),但没有帮助。

请注意,如果我在Windows主机上的linux docker容器内运行相同的代码,则错误将在相同的21秒内返回,但是如果我在linux主机上的linux docker容器内运行该错误,我将得到2分10秒。

0 个答案:

没有答案
相关问题