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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:30:41+00:00 2026-05-17T20:30:41+00:00

First, let me explain a little bit about my setup. My server is setup

  • 0

First, let me explain a little bit about my setup. My server is setup as a Marshaled singleton object:

 RemotingServices.Marshal(lsServer, ServerObject.objectUri);

In order to have two-way communication from the server to the client, the client activates a ServerObject, then passes in its own ClientObject (which is also a MarshalByRefObject) the server uses the ClientObject to talk back to the client:

var lsClient = new ClientObject();

var lsServer = (ServerObject)Activator.GetObject(typeof(ServerObject), url);
lsServer.attach(lsClient);

When the attach method is called, the server takes the ClientObject and stores it in a List:

public void attach(ClientObject client) {
    clientList.Add(client);
}

The server can then call a method on the ClientObject called “SendMessage” to communicate to each client in its list:

foreach(var c in clientList) {
    c.SendMessage("Hello");
}

This works great until a client is encountered that has disconnected. In this case, an error is thrown about the client refusing the connection. I can catch the error, but the problem is I cannot remove the reference to the ClientObject from the server’s List. The following re-throws the “connection refused” exception anytime a client has been disconnected:

clientList.Remove(badClient);

So a couple of questions:

1- Is there a way to detect the connection state of a client without having to catch an error?

2- When I do detect a client that has disconnected, why does the attempt to remove the object from the server’s list appear to “communicate” with the client (thus causing the exception to be thrown again?)

EDIT

As Patrick pointed out below, doing a Remove from a list causes the List to iterate my objects and do a comparison on them (calling .Equals) – this is what caused my ClientObject to attempt to communicate again and thus throw the exception.

To resolve it, I instead changed the List to a dictionary keyed off a unique ID supplied by my Client at the time of attaching to the server. Then I used that unique ID to remove the client.

I never did find a direct way for determining if a client had disconnected other than catching the error.

  • 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-17T20:30:41+00:00Added an answer on May 17, 2026 at 8:30 pm

    Not sure on #2. However, if you’re trying to remove an item from clientList from inside the foreach loop, you can’t. That’s a .NET rule — no changing the contents of an enumerable object while it’s being enumerated.

    Instead, if you catch the error inside the foreach loop, store it in another list (a “disconnected” list). After the foreach, remove all of the disconnected items from the clientList.

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

Sidebar

Related Questions

Alright let me explain my situation first: I am part of an organization that
First, let me explain what I am doing. I need to take an order,
This question might not seem programming related at first, but let me explain. I'm
First let me say that I really feel directionless on this question. I am
First, let's get the security considerations out of the way. I'm using simple authentication
Let's say the first N integers divisible by 3 starting with 9. I'm sure
First, let me use one sentence to let out some frustration: My god, developing
First, let me say that I'm a complete beginner at Python. I've never learned
Let me state first: I know that any user that wants to run a
First off, let me start off that I am not a .net developer. The

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.