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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:19:18+00:00 2026-06-06T21:19:18+00:00

There is a TCP server project I’m working on. It asynchronously listens the specified

  • 0

There is a TCP server project I’m working on.
It asynchronously listens the specified port for connections, accepts new connections and begins to wait for data from them.
Each new client sends its ID when it connects, this way I know which socket belongs to which client.

Minimum of 100000 clients are going to be connected to the server at the same time.

The question is how should I store these clients?

class Client
{
    public Socket Socket { get; set; }
    public int ID { get; set; }
}

Something like List<Client> would definitely break since List<T> is not a thread-safe type. I should add the client to the list when it connects to the server, remove it from the list when the connection is lost. I also need to be able to send a message to the client with the ID of 5, for example and iterating a List<T> in an asynchronous environment is a terrible idea. I think locking a sync root every time that I need to interact with the collection wouldn’t do any good when it comes to performance.

So, what should I use for performance?

Edit: I use .NET 4

  • 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-06T21:19:19+00:00Added an answer on June 6, 2026 at 9:19 pm

    I would use a thread-safe dictionary with the ID as the key. If you’re using .net 4 you can use the System.Collections.Concurrent.ConcurrentDictionary – if not you can either roll your own or check out this url for a nice one that uses reader/writer locks

    http://devplanet.com/blogs/brianr/archive/2008/09/26/thread-safe-dictionary-in-net.aspx

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

Sidebar

Related Questions

There's a threaded TCP server which creates a new thread for each client connection.
I'm working on a server project in C#, and after a TCP message is
I am currently working on a project that creates a TCP socket and listens
There is a very simple socket server implemented by boost::asio . tcp::acceptor a(io_service, tcp::endpoint(tcp::v4(),
I am working on a client-server project and need to implement a logic where
I'm using a TCP Client Server Library called Lacewing. http://lacewing-project.org/docs/ What I noticed is
I saw just what I needed at msdn to create my TCP server,but there
I want to develop one no-blocking tcp server with c++, is there any open
In near future I'll need to start working on a new project that consist
Is there any open source projects to implement efficient and reliable TCP 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.