Benutzer-Werkzeuge

Webseiten-Werkzeuge


csharp:networking_mit_csharp

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
csharp:networking_mit_csharp [2016/08/19 15:19] ronnycsharp:networking_mit_csharp [2016/09/20 23:25] (aktuell) ronny
Zeile 8: Zeile 8:
 |Threadpool|[[https://msdn.microsoft.com/en-us/library/system.threading.threadpool.aspx|Link]]|Wenn man schon mit Worker-Threads arbeiten will...| |Threadpool|[[https://msdn.microsoft.com/en-us/library/system.threading.threadpool.aspx|Link]]|Wenn man schon mit Worker-Threads arbeiten will...|
  
-{{tag>[CSharp Netzwerk Kerberos NTLM]}}+===== Auch noch wichtig =====
  
 +<code>
 +
 +
 +You are calling ReadToEnd on the receiver - however, the sender has not said that it has finished sending - the sender only closes the stream etc after the incoming message that will never come; basically, you've deadlocked yourself.
 +
 +There are many ways to approach this type of problem, including:
 +
 +    using a length-prefix to a message so the receiver knows how much data to expect in advance (and can limit itself accordingly)
 +    using a terminator to a message (maybe a cr/lf) so the receiver knows it has reached the end of a message; for a text protocol, ReadLine may then be useful
 +    closing the outbound stream
 +
 +the last is simple if you are only sending one message; just use:
 +
 +socket.Shutdown(SocketShutdown.Send);
 +
 +after sending the message, and the receiver will know it isn't going to get any more data on the socket. Note also that you must clear down things like the crypto stream before doing this, to ensure the data is actually all sent (and not buffered and lost).
 +
 +Personally, I tend to use the first option (length prefix), mainly because I'm usually dealing in multi-message binary protocols.
 +</code>
 +
 +Quelle: [[http://stackoverflow.com/questions/9659893/c-sharp-send-receive-messages-via-networkstream-simple-code-but-does-not-wo]]
 +
 +**Offensichtlich bedeutet ein NegotiateStream.EndRead nicht, dass die Nachricht auch als abgeschlossen interpretiert wird, sondern lediglich, dass der Buffer soweit es geht gefüllt wird. Wenn man mit BeginRead loslegt, obwohl der Absender nix mehr schickt, landet man in einer Deadlock!**
 +
 +{{tag>[CSharp Netzwerk Kerberos NTLM]}}
csharp/networking_mit_csharp.txt · Zuletzt geändert: 2016/09/20 23:25 von ronny

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki