Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 278267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T01:12:43+00:00 2026-05-12T01:12:43+00:00

When the Client tries to connect to a disconnected IP address, there is a

  • 0

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 configure 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();
    }
}
catch (SocketException se)
{
    lb_connectStatus.Text = "Connection Failed";
    MessageBox.Show(se.Message);
}
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T01:12:44+00:00Added an answer on May 12, 2026 at 1:12 am

    I solved the problem by using Socket.ConnectAsync Method instead of Socket.Connect Method.
    After invoking the Socket.ConnectAsync(SocketAsyncEventArgs), start a timer (timer_connection), if time is up, check whether socket connection is connected (if(m_clientSocket.Connected)), if not, pop up timeout error.

    private void connect(string ipAdd,string port)
        {
            try
            {
                SocketAsyncEventArgs e=new SocketAsyncEventArgs();
    
    
                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.
                e.RemoteEndPoint = ipEnd;
                e.UserToken = m_clientSocket;
                e.Completed+=new EventHandler<SocketAsyncEventArgs>(e_Completed);                
                m_clientSocket.ConnectAsync(e);
    
                if (timer_connection != null)
                {
                    timer_connection.Dispose();
                }
                else
                {
                    timer_connection = new Timer();
                }
                timer_connection.Interval = 2000;
                timer_connection.Tick+=new EventHandler(timer_connection_Tick);
                timer_connection.Start();
            }
            catch (SocketException se)
            {
                lb_connectStatus.Text = "Connection Failed";
                MessageBox.Show(se.Message);
            }
        }
    private void e_Completed(object sender,SocketAsyncEventArgs e)
        {
            lb_connectStatus.Text = "Connection Established";
            WaitForServerData();
        }
        private void timer_connection_Tick(object sender, EventArgs e)
        {
            if (!m_clientSocket.Connected)
            {
                MessageBox.Show("Connection Timeout");
                //m_clientSocket = null;
    
                timer_connection.Stop();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I get the ip address of a client when he tries to
I have written an ActionScript client program that tries to connect to a local
My android aplication tries to connect to a service using response = client.execute(getRequest); However
I'm using python 2.7 on an ubuntu machine. The client tries to connect to
I have a server app and sometimes, when the client tries to connect, I
I'm getting following error when my client tries to connect to my server socket:
I am running a simple Java client to connect to a remote MQ queue.
I have some kind of problem and I can't check this at home if
My application times out while trying to connect to host. The timeout time is
Okay I know there is lots of info out there on this and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.