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

  • Home
  • SEARCH
  • 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 7090467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:03:29+00:00 2026-05-28T08:03:29+00:00

We have an application in production that is supposed to be a multithreaded socket

  • 0

We have an application in production that is supposed to be a multithreaded socket listener. I am starting to have my doubts because the logs the app generates makes it appear as if it is processing the streams it receives synchronously. In an effort of trying not to paste a wall of code here, I will supply the first portion of supposedly asynch tcp code: Is this proper practice?

        /// <summary>
        /// Start an Asynchronous Socket to listen for connections. 
        /// </summary>
        public static void StartListening()
        {
            Socket listenerSocket = null;

            try
            {
                var ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
                var ipAddress = ipHostInfo.AddressList[Socket.OSSupportsIPv6 ? 1 : 0];

                //Create TCP/IP Socket
                listenerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                listenerSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
                listenerSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, 1);

                //Bind the socket to the local endpoint and listen for incoming connections.
                //listenerSocket.Bind(new IPEndPoint(ipAddress, m_client.RemotePort));
                listenerSocket.Bind(new IPEndPoint(ipAddress, Int32.Parse(ConfigurationManager.AppSettings["ListenerPort"])));
                listenerSocket.Listen(m_maxSocketConnections);

                while (true)
                {
                    //Set the event to nonsignaled state
                    m_pAllDone.Reset();

                    //Start an asynchronous socket 
                    listenerSocket.BeginAccept(new AsyncCallback(AcceptCallback), listenerSocket);

                    //Wait until a connection is made and processed before continuing
                    m_pAllDone.WaitOne();
                }
            } 
  • 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-05-28T08:03:30+00:00Added an answer on May 28, 2026 at 8:03 am

    This call is not multithreaded, it is simply asynchronous. From the docs:

    When your application calls BeginAccept, the system usually uses a separate thread to execute the specified callback method and blocks on EndAccept until a pending connection is retrieved.

    The BeginAccept method creates one other thread that blocks and processes the incoming packets asynchronously. It does not spawn a NEW thread every time a message comes in.

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

Sidebar

Related Questions

I have a production application that consists of An app server VM1 - 192.168.0.4
I have a VB6's Application that is in production environment right now, this application
I have application that makes different queries with different results so the caching in
I have java application that is crashing while in production. It doesn't do so
We currently have a production application that runs as a windows service. Many times
I have a .NET Windows application in the production that has no access to
We have an application written in C# .NET that is currently used in production
I have a large application in a production environment that I'm trying to move
I have an application that I have written to view logs from custom applications
I have an application in production that that recently had a MySQL timeout, so

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.