Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF prevent server disconnect
    primarykey
    data
    text
    <p>I have a small client/server application. I was using a hand-coded TCP connection to allow the client to control the server, but now I've converted it to WCF. This saved me a whole bunch of code, but it also gave me a whole new set of problems to fix...</p> <p>The latest problem is that after a while, the server disconnects the client. I do <em>not</em> want this to ever happen, under any circumstances. Currently the client gets about a quarter of the way through its run, and then explodes with fire because the server has dropped the connection. I need to stop this happening.</p> <p>I was able to write a trivial WCF client/server pair that replicates the problem. It seems that if the client calls a method, waits 15 minutes, and then calls a second method, the second call throws an exception babbling something about the socket having been closed. If I reduce the delay, everything works fine.</p> <p>I read in another answer somewhere that setting <code>ReceiveTimeout</code> should fix this. However, when I tried it, this only fixes the problem under .NET; when running under Mono, it still breaks. Since Mono is the actual target platform, this isn't very helpful.</p> <p>(Think about SSH - you would <em>not</em> want an SSH server to disconnect you just because you didn't type anything for a while. Perhaps you issued a long-running shell command or something... Just because the <em>server</em> hasn't received any data from you doesn't mean nothing is happening! It certainly doesn't mean your connection should get dropped...)</p> <p>All code is C#. The server is a self-hosting console app. The client is also a console app. All configuration is in code. Binding is <code>NetTcpBinding</code> with default settings.</p> <p>What can I do to allow the client to run to completion successfully?</p> <p>I have a few ideas, but none of them are pretty:</p> <ul> <li>Manually send heartbeat messages. (Yuck!)</li> <li>Detect disconnection and automatically reconnect? (Again, yuck.)</li> <li>Turn on "reliable mode". (I'm guessing that since the server <em>deliberately</em> ends the session, this won't help.)</li> <li>Create one connection per method call. (That's going to be quite a lot of code...)</li> <li>Stop using WCF?</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload