How to config socket connect timeout in C#

Posted by ninikin on Stack Overflow See other posts from Stack Overflow or by ninikin
Published on 2009-06-30T06:30:49Z Indexed on 2010/04/17 10:03 UTC
Read the original article Hit count: 880

Filed under:
|
|

(C# )When the Client tries to connect to a disconnected IP address, there is a long timeout over 15 seconds... How can we reduce this timeout? What is the method to config it?

The code I'm using to set up a socket connection is as following:

try
        {
            m_clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPAddress ip = IPAddress.Parse(serverIp);
            int iPortNo = System.Convert.ToInt16(serverPort);
            IPEndPoint ipEnd = new IPEndPoint(ip, iPortNo);
            m_clientSocket.Connect(ipEnd);
            if (m_clientSocket.Connected)
            {
                lb_connectStatus.Text = "Connection Established";
                WaitForServerData();
            }
            else
            {

            }
        }
        catch (SocketException se)
        {
            lb_connectStatus.Text = "Connection Failed";
            MessageBox.Show(se.Message);
        }

© Stack Overflow or respective owner

Related posts about c#

Related posts about sockets