.NET Framework Bookmark and Share   
 index > .NET Remoting and Runtime Serialization > How to prevent System.Net.Sockets.SocketException in the server when a client exits
 

How to prevent System.Net.Sockets.SocketException in the server when a client exits

I have a very simple client/server solution that uses a wellknown singleton and a TcpChannel. Basically just copy/paste from the docs.

I noticed that when a client exists, the server throws twice an exception System.Net.Sockets.SocketException. I guess this is because it keeps a proxy to a client that does not exist anymore. These exceptions do not cause a crash, they are trapped inside remoting I think. They only appear in the debug output window.

This issue has been posted before, but no solution has been given.

So basically, if a client does Activator.GetObject(), how should it "disconnect" from the server so that the latter does not throw these exceptions? Personally I think this should automatically be handled when the proxy is garbage collected.

Chatterbox
We are having the same problem. Does anyone have an answer to this thread?

// unregister the channel

ChannelServices.UnregisterChannel(this.clientChannel);

// if you have a delegate event handler for communication purposes:

_CallbackSink.OnHostToClient -= callbackSinkOnClient;

// set the object that hosted the remoting object to null.

gmmgruber
We are having the same problem. Does anyone have an answer to this thread?
integragreg
The OP said that he was getting this exception printed to the debug console but wasnt causing any negative side effects, is that true for you as well? If so, what would you like us to solve here? It sounds like its working correctly in this case.
Darren Headrick-MSFT
We are having the same problem. Does anyone have an answer to this thread?

// unregister the channel

ChannelServices.UnregisterChannel(this.clientChannel);

// if you have a delegate event handler for communication purposes:

_CallbackSink.OnHostToClient -= callbackSinkOnClient;

// set the object that hosted the remoting object to null.

gmmgruber
Above solution not working for me for any of the given MS samples.


I guess what i'm after is a correct understanding of whats happening.

In my server's trace viewer in debug mode i see 2: System.Net.Sockets.SocketException instances.

This always happens when the client disconnects after invoking instances of remotable objects (Register client activated type )

Should I be worried about this log msg or is it what .NET is expected to do? i.e, it deliberately uses.NETexception handling to detect when a client has shutdown/discarded its connection resources.

I did enable the handling of first chance exception handling for the above exception type and managed to gleam one line of additional debug trace - "The client or remote hostwas forcibly disconnected" or something like that. That sounds like the client threw away its connection and was very naughty, but not to worry, .NET detected this and handled it nicely for you.

Some clarrification on this issue would be nice ( if there is any ). I would certainly prefer not to encounter any first chance exceptions in this scenarioby having the ability to cleanly shutdown a remoted object's connection.
elimn8or

You can use google to search for other answers

Custom Search

More Threads

• XML serialization is slower than Binary. Can anyone explain why ?
• wich technology is better for distebuted program (acsses from web and win base prg)
• .Net Remoting-Server Callback Its Clients By Initiative Way
• Enable button on cellchange of grid
• Internals of remote object creation
• .Remoting
• Passing COM interfaces via NET Remoting methods
• IPC Channel + Windows Service + Server 2003 = ?
• .NET Remoting RemotingException
• Calling Remote objects without proxy object