(Non Blocking) Socket BeginReceive Continues receiving not throwing Error when disconnect network

viralchauhanviralchauhan USMember
edited December 2016 in Visual Studio

Hello,

I trying to make client Socket communication in (Xamarin.Shared) project common for iOS and Android.

I have use System.Net.Sockets.Socket Class with all non - blocking (Async) methods (like Begin*).

I trying to Receive continues data using BeginReceive ** and **receiveCallback

like

IAsyncResult asyncReceive = clientSocket.BeginReceive( stateObject.sBuffer, 0, stateObject.sBuffer.Length, SocketFlags.None, new AsyncCallback(receiveCallback), stateObject);

And

public static void receiveCallback(IAsyncResult asyncReceive)
{
StateObject stateObject =
(StateObject)asyncReceive.AsyncState;

  int bytesReceived = stateObject.sSocket.EndReceive(asyncReceive);

 if (bytesReceived > 0)
{
    // There  might be more data .Here, you need to Receive again
    clientSocket.BeginReceive(stateObject.buffer, 0, RemainingData.BufferSize, SocketFlags.None ,new AsyncCallback(receiveCallback), stateObject);
} 

}

  • In this all working fine and data download continuously, but when any kind of network failure (like Wifi OFF) then this cycle is stop working.
  • Also no socketException throws by Socket.

  • How i can get intimation of network fail in continues receiving mode ?

  • Pls suggestion in Xamarin Framework.

Thanks
In Adavance

Sign In or Register to comment.