<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">I'm wondering if this is a bug..... 
      And maybe a report should be filed....  Sounds like a similar
      problem i looked at recently, but that bug was different because
      the sample code in the bug report also crashed in windows.<br>
      <br>
      According to: 
      <meta http-equiv="content-type" content="text/html;
        charset=ISO-8859-1">
      <a
href="http://www.codeproject.com/Articles/8580/How-to-detect-a-connection-loss-in-Net-Sockets">http://www.codeproject.com/Articles/8580/How-to-detect-a-connection-loss-in-Net-Sockets</a>
      <br>
      <br>
      The way to detect a remotely closed connection is to check if
      Socket.Receive (which, incidentally, is the topmost thing on the
      stack below) returns 0 or fewer bytes -- so you wouldn't expect an
      exception, instead you would expect a 0 return for number of bytes
      read.<br>
      <br>
      This would seem to match:<br>
      <meta http-equiv="content-type" content="text/html;
        charset=ISO-8859-1">
      <br>
      <a href="http://msdn.microsoft.com/en-us/library/w3xtz6a5.aspx">http://msdn.microsoft.com/en-us/library/w3xtz6a5.aspx</a><br>
      <br>
      Which says:<br>
      <br>
      "
      <meta http-equiv="content-type" content="text/html;
        charset=ISO-8859-1">
      <span style="color: rgb(0, 0, 0); font-family: 'Segoe UI',
        Verdana, Arial; font-size: 13px; font-style: normal;
        font-variant: normal; font-weight: normal; letter-spacing:
        normal; line-height: normal; orphans: 2; text-align: left;
        text-indent: 0px; text-transform: none; white-space: normal;
        widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto;
        -webkit-text-stroke-width: 0px; display: inline !important;
        float: none; ">If the remote host shuts down the<span
          class="Apple-converted-space"> </span></span><span
        style="color: rgb(0, 0, 0); font-family: 'Segoe UI', Verdana,
        Arial; font-size: 13px; font-style: normal; font-variant:
        normal; font-weight: normal; letter-spacing: normal;
        line-height: normal; orphans: 2; text-align: left; text-indent:
        0px; text-transform: none; white-space: normal; widows: 2;
        word-spacing: 0px; -webkit-text-size-adjust: auto;
        -webkit-text-stroke-width: 0px; "><a
href="http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx"
          style="color: rgb(150, 11, 180); text-decoration: none; ">Socket</a></span><span
        style="color: rgb(0, 0, 0); font-family: 'Segoe UI', Verdana,
        Arial; font-size: 13px; font-style: normal; font-variant:
        normal; font-weight: normal; letter-spacing: normal;
        line-height: normal; orphans: 2; text-align: left; text-indent:
        0px; text-transform: none; white-space: normal; widows: 2;
        word-spacing: 0px; -webkit-text-size-adjust: auto;
        -webkit-text-stroke-width: 0px; display: inline !important;
        float: none; "><span class="Apple-converted-space"> </span>connection
        with the<span class="Apple-converted-space"> </span></span><span
        style="color: rgb(0, 0, 0); font-family: 'Segoe UI', Verdana,
        Arial; font-size: 13px; font-style: normal; font-variant:
        normal; font-weight: normal; letter-spacing: normal;
        line-height: normal; orphans: 2; text-align: left; text-indent:
        0px; text-transform: none; white-space: normal; widows: 2;
        word-spacing: 0px; -webkit-text-size-adjust: auto;
        -webkit-text-stroke-width: 0px; "><a
href="http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.shutdown.aspx"
          style="color: rgb(150, 11, 180); text-decoration: none; ">Shutdown</a></span><span
        style="color: rgb(0, 0, 0); font-family: 'Segoe UI', Verdana,
        Arial; font-size: 13px; font-style: normal; font-variant:
        normal; font-weight: normal; letter-spacing: normal;
        line-height: normal; orphans: 2; text-align: left; text-indent:
        0px; text-transform: none; white-space: normal; widows: 2;
        word-spacing: 0px; -webkit-text-size-adjust: auto;
        -webkit-text-stroke-width: 0px; display: inline !important;
        float: none; "><span class="Apple-converted-space"> </span>method,
        and all available data has been received, the<span
          class="Apple-converted-space"> </span></span><span
        style="color: rgb(0, 0, 0); font-family: 'Segoe UI', Verdana,
        Arial; font-size: 13px; font-style: normal; font-variant:
        normal; font-weight: normal; letter-spacing: normal;
        line-height: normal; orphans: 2; text-align: left; text-indent:
        0px; text-transform: none; white-space: normal; widows: 2;
        word-spacing: 0px; -webkit-text-size-adjust: auto;
        -webkit-text-stroke-width: 0px; "><a
href="http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.receive.aspx"
          style="color: rgb(150, 11, 180); text-decoration: none; ">Receive</a></span><span
        style="color: rgb(0, 0, 0); font-family: 'Segoe UI', Verdana,
        Arial; font-size: 13px; font-style: normal; font-variant:
        normal; font-weight: normal; letter-spacing: normal;
        line-height: normal; orphans: 2; text-align: left; text-indent:
        0px; text-transform: none; white-space: normal; widows: 2;
        word-spacing: 0px; -webkit-text-size-adjust: auto;
        -webkit-text-stroke-width: 0px; display: inline !important;
        float: none; "><span class="Apple-converted-space"> </span>method
        will complete immediately and return zero bytes."<br>
        <br>
        And also says that SocketException is only raised under certain
        conditions, the only almost valid match is:<br>
      </span><br>
      <meta http-equiv="content-type" content="text/html;
        charset=ISO-8859-1">
      "An operating system error occurs while accessing the<span
        class="Apple-converted-space"> </span><span><a
href="http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx"
          style="color: rgb(150, 11, 180); text-decoration: none; ">Socket</a></span>."<br>
      <br>
      But i don't think connection reset by peer is necessarily an
      operating system exception, it's rather a state of connection
      indicating we're disconnected, hence we should be returning zero,
      not raising an exception.<br>
      <br>
      -Rob<br>
      <br>
      On 06/26/2012 08:49 AM, shahbour wrote:<br>
    </div>
    <blockquote cite="mid:1340714962865-4650173.post@n4.nabble.com"
      type="cite">
      <pre wrap="">Hello

I got an WCF service that is running except at some time if the client send
a request then close his program directly , ending the session the WCF
console application crashes with below error 


[0x7f0b42f55700:] EXCEPTION handling: System.Net.Sockets.SocketException:
Connection reset by peer
[0x7f0b42f55700:] EXCEPTION handling: System.IO.IOException: Read failure
[0x7f0b42f55700:] EXCEPTION handling: System.IO.IOException: Read failure

Unhandled Exception: System.IO.IOException: Read failure --->
System.Net.Sockets.SocketException: Connection reset by peer
  at System.Net.Sockets.Socket.Receive (System.Byte[] buffer, Int32 offset,
Int32 size, SocketFlags flags) [0x000ad] in
/usr/local/src/mono-2.11.1/mcs/class/System/System.Net.Sockets/Socket.cs:1606
  at System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, Int32
offset, Int32 size) [0x00067] in
/usr/local/src/mono-2.11.1/mcs/class/System/System.Net.Sockets/NetworkStream.cs:399
  --- End of inner exception stack trace ---
  at System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, Int32
offset, Int32 size) [0x00078] in
/usr/local/src/mono-2.11.1/mcs/class/System/System.Net.Sockets/NetworkStream.cs:401
  at System.Net.RequestStream.Read (System.Byte[] buffer, Int32 offset,
Int32 count) [0x0003c] in
/usr/local/src/mono-2.11.1/mcs/class/System/System.Net/RequestStream.cs:142
  at System.IO.StreamReader.ReadBuffer () [0x00012] in
/usr/local/src/mono-2.11.1/mcs/class/corlib/System.IO/StreamReader.cs:394
  at System.IO.StreamReader.Read (System.Char[] buffer, Int32 index, Int32
count) [0x00062] in
/usr/local/src/mono-2.11.1/mcs/class/corlib/System.IO/StreamReader.cs:471
  at Mono.Xml2.XmlTextReader.ReadTextReader (Int32 remained) [0x0004f] in
/usr/local/src/mono-2.11.1/mcs/class/System.XML/System.Xml/XmlTextReader.cs:1256
  at Mono.Xml2.XmlTextReader.PeekChar () [0x00047] in
/usr/local/src/mono-2.11.1/mcs/class/System.XML/System.Xml/XmlTextReader.cs:1210
  at Mono.Xml2.XmlTextReader.ReadContent () [0x0003f] in
/usr/local/src/mono-2.11.1/mcs/class/System.XML/System.Xml/XmlTextReader.cs:1310
  at Mono.Xml2.XmlTextReader.Read () [0x00141] in
/usr/local/src/mono-2.11.1/mcs/class/System.XML/System.Xml/XmlTextReader.cs:626
  at System.Xml.XmlTextReader.Read () [0x0006b] in
/usr/local/src/mono-2.11.1/mcs/class/System.XML/System.Xml/XmlTextReader2.cs:564
  at System.Xml.XmlSimpleDictionaryReader.Read () [0x00000] in
/usr/local/src/mono-2.11.1/mcs/class/System.Runtime.Serialization/System.Xml/XmlSimpleDictionaryReader.cs:253
  at System.Xml.XmlReader.MoveToContent () [0x00050] in
/usr/local/src/mono-2.11.1/mcs/class/System.XML/System.Xml/XmlReader.cs:574
  at System.ServiceModel.Channels.XmlReaderMessage.ReadEnvelopeStart ()
[0x00000] in
/usr/local/src/mono-2.11.1/mcs/class/System.ServiceModel/System.ServiceModel.Channels/MessageImpl.cs:146
  at System.ServiceModel.Channels.XmlReaderMessage..ctor
(System.ServiceModel.Channels.MessageVersion version,
System.Xml.XmlDictionaryReader reader, Int32 maxSizeOfHeaders) [0x00026] in
/usr/local/src/mono-2.11.1/mcs/class/System.ServiceModel/System.ServiceModel.Channels/MessageImpl.cs:70
  at System.ServiceModel.Channels.Message.CreateMessage
(System.Xml.XmlDictionaryReader envelopeReader, Int32 maxSizeOfHeaders,
System.ServiceModel.Channels.MessageVersion version) [0x00022] in
/usr/local/src/mono-2.11.1/mcs/class/System.ServiceModel/System.ServiceModel.Channels/Message.cs:427
  at System.ServiceModel.Channels.TextMessageEncoder.ReadMessage
(System.IO.Stream stream, Int32 maxSizeOfHeaders, System.String contentType)
[0x00011] in
/usr/local/src/mono-2.11.1/mcs/class/System.ServiceModel/System.ServiceModel.Channels/TextMessageEncoder.cs:87
  at System.ServiceModel.Channels.Http.HttpReplyChannel.CreatePostMessage
(System.ServiceModel.Channels.Http.HttpContextInfo ctxi) [0x00081] in
/usr/local/src/mono-2.11.1/mcs/class/System.ServiceModel/System.ServiceModel.Channels.Http/HttpReplyChannel.cs:229
  at System.ServiceModel.Channels.Http.HttpReplyChannel.TryReceiveRequest
(TimeSpan timeout, System.ServiceModel.Channels.RequestContext& context)
[0x000aa] in
/usr/local/src/mono-2.11.1/mcs/class/System.ServiceModel/System.ServiceModel.Channels.Http/HttpReplyChannel.cs:172
  at
System.ServiceModel.Channels.ReplyChannelBase.<BeginTryReceiveRequest>m__10
(TimeSpan tout, System.ServiceModel.Channels.RequestContext& ctx) [0x0002f]
in
/usr/local/src/mono-2.11.1/mcs/class/System.ServiceModel/System.ServiceModel.Channels/ReplyChannelBase.cs:126

I couldn't figure out how to check the connection status before trying to
ReadMessage or CreatePostMessage functions.

Any Help ??


--
View this message in context: <a class="moz-txt-link-freetext" href="http://mono.1490590.n4.nabble.com/WCF-Fail-with-System-Net-Sockets-SocketException-Connection-reset-by-peer-tp4650173.html">http://mono.1490590.n4.nabble.com/WCF-Fail-with-System-Net-Sockets-SocketException-Connection-reset-by-peer-tp4650173.html</a>
Sent from the Mono - Dev mailing list archive at Nabble.com.
_______________________________________________
Mono-devel-list mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Mono-devel-list@lists.ximian.com">Mono-devel-list@lists.ximian.com</a>
<a class="moz-txt-link-freetext" href="http://lists.ximian.com/mailman/listinfo/mono-devel-list">http://lists.ximian.com/mailman/listinfo/mono-devel-list</a>
</pre>
    </blockquote>
    <br>
    <br>
  </body>
</html>