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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:36:38+00:00 2026-05-14T03:36:38+00:00

We are writing a socket server in c# and need some advice on the

  • 0

We are writing a socket server in c# and need some advice on the design.

Background: Clients (from mobile devices) connect to our server app and we leave their socket open so we can send data back down to them whenever we need to. The amount of data varies but we generally send/receive data from each client every few seconds, so it’s quite intensive. The amount of simultaneous connections can range from 50-500 (and more in the future).

We have already written a server app using async sockets and it works, however we’ve come across some stumbling blocks and we need to make sure that what we’re doing is correct.

We have a collection which holds our client states (we have no socket/connection pool at the moment, should we?).

Each time a client connects we create a socket and then wait for them to send us some data and in receiveCallBack we add their clientstate object to our connections dictionary (once we have verified who they are).

When a client object then signs off we shutdown their socket and then close it as well as remove them from our collection of clients dictionary.

Presumably everything happens in the right order, everything works as expected.

However, almost everyday it stops accepting connections, or so we think, either that or it connects but doesn’t actually do anything past that and we can’t work out why it’s just stopping.

There are few things that we’r’e unsure about

1) Should we be creating some kind of connection pool as opposed to just a dictionary of client sockets

2) What happens to the sockets that connect but then don’t get added to our dictionary, they just linger around in memory doing nothing, should we create ANOTHER dictionary that holds the sockets as soon as they are created?

3) What’s the best way of finding if clients are no longer connected? We’ve read some many methods but we’re not sure of the best one to use, send data or read data, if so how?

4) If we loop through the connections dictonary to check for disposed clients, should we be locking the dictionary, if so how does this affect other clients objects trying to use it at the same time, will it throw an error or just wait?

5) We often get disposedSocketException within ReceiveCallBack method at random times, does this mean we are safe to remove that socket from the collection?

We can’t seem to find any production type examples which show any of this working.

Any advice would be greatly received

  • 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-14T03:36:38+00:00Added an answer on May 14, 2026 at 3:36 am

    4) Yes, lock it. The other threads will just have to wait.

    In general, you have to lock the dictionary with each access, including reads. Otherwise, the structure can become corrupted, which is one possible cause for your problems.

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

Sidebar

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.