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 8764971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:10:04+00:00 2026-06-13T16:10:04+00:00

I have an asynchronous socket server and client. If I tell the client to

  • 0

I have an asynchronous socket server and client. If I tell the client to make 20,000 connections to the server I receive “No connection could be made because the target machine actively refused it” for about 25-30% of the connections. This is totally to be expected as I am hammering the listening socket and the backlog queue is filling up.

The question I have is: What do I do when I get this exception? How should I handle the connections, should I be shutting down and closing the socket and then trying to reconnect? Or will TCP try to reconnect via its own mechanism within the protocol?

Here is my code OnConnected function which is the AsyncCallbak for BeginConnect() and it is where I am handling the exception:

    void OnConnected(IAsyncResult ar)
    {
        Socket client = (Socket)ar.AsyncState;

        try
        {                
            client.EndConnect(ar);
            SocketState state = new SocketState(client, m_certValidationCallback);

            state.sslStream.BeginAuthenticateAsClient(m_remoteHostName, m_clientCertificates, m_sslProtocols, m_checkCertificateRevocation,
                    m_onAuthenticateAsClient, state);
        }
        catch (Exception ex)
        {
            //m_connectionCallback(this, new SecureConnectionResults(ex));

           //What do I do here?
            if (client != null)
            {
                client.Shutdown(SocketShutdown.Both); //This causes an exception
                client.Close();
                client.Dispose();
            }
        }
    }

Trying to shutdown the socket in the catch, causes another exception: “A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied”

According to this exception, it appears the socket is not connected. Once again, is it going to try to reconnect on its own based on the TCP protocol? Or should I just re-queue the connection and try again?

  • 1 1 Answer
  • 0 Views
  • 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-06-13T16:10:05+00:00Added an answer on June 13, 2026 at 4:10 pm

    I would catch a more specific exception, and not call Shutdown() under this condition. TCP will not reconnect for you. You will have to retry this connection yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have TCP Socket server and would like to make asynchronous Silverlight client for
I have created this asynchronous client socket that connects to a server and keeps
I have got a Client/Server Application that using Asynchronous Socket.My problem is i cant
I currently work on a server/client program based on asynchronous socket. As far as
I have a fairly generic C# socket server that uses the asynchronous methods of
I have an asynchronous socket server. I have encountered a issue where problematic clients
I have a C# Asynchronous socket server, like so: private Socket _serverSocket; _serverSocket =
I have a client / server application made with C#. Its working fine when
I have a C# TCP Asynchronous socket server. Testing locally, I can accept 5K
I currently have an asynchronous TCP/IP socket C# WinForms application that is the Server

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.