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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:28:18+00:00 2026-05-21T15:28:18+00:00

I have been working with the following code published on msdn: http://msdn.microsoft.com/en-us/library/fx6588te.aspx I understand

  • 0

I have been working with the following code published on msdn:

http://msdn.microsoft.com/en-us/library/fx6588te.aspx

I understand that the server application is not blocked whilst the application is waiting for new clients.

However can this application (or even sockets) for that matter handle multiple concurrent requests?

  • What would happen if client A and B connected at the same time?

  • If client A connects and the handling of its request takes 5 seconds, if client B connects a second later must it wait for client A to finish before its processing can start?

  • Or will client A and client B’s requests be handled concurrently?

I have done some testing with this by putting Thread.Sleep(n) commands in between the receive/send data in the socket listener code. I can then send multiple requests to the socket and they appear to be handled. However the socket always handles them on the same thread id – which makes me believe that it isnt actually happening concurrently.

Especially given the description by microsoft that this app simply doesnt block whilst awaiting for new connections – does that mean it can handle concurrent connections?

  • 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-21T15:28:19+00:00Added an answer on May 21, 2026 at 3:28 pm

    [Update 2014]: It seems that the example has been modified since this answer was posted, as noted in this thread. The MSDN example now handles multiple incoming connections properly. Anyway, the general approach described here is correct and perhaps it can provide additional clarification.


    When doing socket communication, you basically have a single listener socket for all incoming connections, and multiple handler sockets for each connected client.

    Listening to incoming connections

    When you start listening to a port, you create a socket with a callback method for incoming connections (this is referencing the example you mentioned). That’s the one-and-only listener socket for that port number:

    listener.BeginAccept(new AsyncCallback(AcceptCallback), listener);
    

    This line tells the listener to invoke the AcceptCallback method whenever a new client is connected (new connection callback). That method is the one which should do its work quickly, since it blocks other incoming connections.

    Creating dedicated handler sockets

    That is also why AcceptCallback must immediately create a dedicated “handler” socket with its own background data callback method (ReadCallback):

    // inside AcceptCallback, we switch to the handler socket for communication
    handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
        new AsyncCallback(ReadCallback), state); // fired on a background thread
    

    From that moment on, ReadCallback method is invoked whenever some data is received by your newly connected client.

    Also, before returning, AcceptCallback needs to call listener.BeginAccept again, to continue listening to new incoming connections:

    // this is the same server socket we opened previously, which will now 
    // continue waiting for other client connections: it doesn't care about
    // the actual data transmission between individual clients
    listener.BeginAccept(new AsyncCallback(AcceptCallback), listener);
    

    This part is omitted from the MSDN example, meaning it can only receive a single connection.

    Receiving data

    As soon as you get a packet of data from your client, ReadCallback method will be invoked. So, inside this data callback method, you need to read and process the received data, and then invoke the same BeginReceive method again (again, with ReadCallback as its data callback method).

    [Edit]

    The problem with MSDN example is that it allows connection of only a single client (listener.BeginAccept is called only once). To allow mulitple concurrent connections, you need to create a receive socket using handler.BeginReceive, and then call listener.BeginAccept to start listening to new clients.

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

Sidebar

Related Questions

No related questions found

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.