TCP connection timeout

0

I get a connection timeout after about 20 seconds. Where is this specified and can it be changed?

Here is a sample code. The ip 192.168.1.200 does not exist!

internal class Program
{
    private static TcpClient _tcp;

    private static void Main(string[] args)
    {
        Stopwatch sw = new Stopwatch();
        sw.Start();
        try
        {
            _tcp = new TcpClient("192.168.1.200", 81);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        sw.Stop();
        Console.WriteLine(sw.ElapsedMilliseconds.ToString());

        Console.ReadLine();
    }
}

The exception is:

System.Net.Sockets.SocketException (0x80004005): 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 192.168.1.200:81 at System.Net.Sockets.TcpClient..ctor(String hostname, Int32 port) at TestTcp.Program.Main(String[] args) in E:\Users\ame\source\repos\TestTcp\TestTcp\Program.cs:line 21

And the stopwatch time in milliseconds is: 21045

The time varies a bit but is around 20 seconds

I'm using Windows 10 and C#

windows
tcpclient
socketexception
asked on Stack Overflow Oct 17, 2020 by Andis59

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0