Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are getting an exception from <code>handler.EndReceive()</code>. While admittedly it is unclear <em>why</em> you’re receiving the specific exception you mentioned, when put into production this code <em>will</em> throw exceptions every time there is a network communication problem (which is common).</p> <p>Therefore, you should probably put a try/catch around the call to <code>EndReceive()</code> anyway. Think about what your code would need to do whenever the connection fails or the server dies or whatever.</p> <p>Then you can start diagnosing specific problems. One important thing you haven’t specified: do you get this error only <em>occasionally</em> or do you reproducibly get it <em>all the time</em>? If it’s the former, then it might just be normal Internet connectivity fluctuations. Your software will have to be able to handle those. If it’s the latter, then I think it sounds like a problem on the server. When you call <code>BeginReceive()</code>, your system will start waiting for something from the server; if that “something” is that it received data, then <code>EndReceive()</code> will succeed, but if that “something” is that the server has <em>closed the connection</em>, your callback will still be invoked, and then <code>EndReceive()</code> will throw the relevant <code>SocketException</code>. This is by design because there’s pretty much no other way to communicate to your code that the server has closed the connection.</p> <p><strong>EDIT:</strong> Looks like your server code needs the same error handling: its call to <code>EndReceive()</code> is equally prone to throwing an exception if the <em>client</em> closes the connection. (I know you have a try/catch around the whole big thing, but it outputs a <em>MessageBox</em>... that is not going to work well on a server, unless you want someone sitting there all the time clicking on all the OK buttons...)</p>
 

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