Remoting - Detect a crashed/disconnected client from the server?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JamesB

    Remoting - Detect a crashed/disconnected client from the server?

    OK, after lots of faffing I have finally gotten remoting working - basically
    I have a windows service (the "server") and a forms app (the "client").

    The forms app can call methods in the server, and I can get events fired on
    the server to be picked up and acted on in the client app, so all is well. I
    can even get two client apps on different machines talking to the same
    server instance and the events pop up on both.

    This is all good until the "first" client app instance dies unexpectedly
    (i.e. for testing, I am just killing it in task manager). The events never
    reach the other instance, as the server seems to be sending out the events
    synchronously to any connected clients. (I have got some code to unregister
    the client/event in the form close event, so if you quit "gracefully " this
    problem doesn't occur).

    Is there any way of either a) removing a crashed client from the servers
    internal list? (I do get an exception in the server when my event is fired,
    basically saying the target machine actively refused connection - but what
    to do with that info!) or b) can I send out my events from the server in
    some async/simultaneous way so it doesn't matter if a client instance has
    died or not.

    I'd prefer option a as it seems neater, but hey-ho.

    TIA

    James.

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Remoting - Detect a crashed/disconnected client from the server?

    James,

    When you get the reference to the client, you have an object that
    derives from MarshalByRefObj ect. With that, you can call GetLifeTimeServ ice
    which will return an object. This object can be cast to an ILease instance
    which you would then query to get the state of the connection back to the
    client. If the state indicates that it is not connected (or an exception is
    thrown), then you can try and unsubscribe through the ILease interface, and
    proceed from there.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "JamesB" <jamesb@somewhe re.com.net.com. netwrote in message
    news:47c32c07$0 $2448$fa0fcedb@ news.zen.co.uk. ..
    OK, after lots of faffing I have finally gotten remoting working -
    basically I have a windows service (the "server") and a forms app (the
    "client").
    >
    The forms app can call methods in the server, and I can get events fired
    on the server to be picked up and acted on in the client app, so all is
    well. I can even get two client apps on different machines talking to the
    same server instance and the events pop up on both.
    >
    This is all good until the "first" client app instance dies unexpectedly
    (i.e. for testing, I am just killing it in task manager). The events never
    reach the other instance, as the server seems to be sending out the events
    synchronously to any connected clients. (I have got some code to
    unregister the client/event in the form close event, so if you quit
    "gracefully " this problem doesn't occur).
    >
    Is there any way of either a) removing a crashed client from the servers
    internal list? (I do get an exception in the server when my event is
    fired, basically saying the target machine actively refused connection -
    but what to do with that info!) or b) can I send out my events from the
    server in some async/simultaneous way so it doesn't matter if a client
    instance has died or not.
    >
    I'd prefer option a as it seems neater, but hey-ho.
    >
    TIA
    >
    James.

    Comment

    Working...