コード例 #1
0
    private void RecieveMessage(IAsyncResult ar)
    {
        int recievedBytes       = _Connection.Client.EndReceive(ar);
        BufferStateObject state = ar.AsyncState as BufferStateObject;

        byte[] data = new byte[recievedBytes];
        Array.Copy(state.buffer, data, recievedBytes);
        MainThreadDispatcher.Instance.RunOnMainThread(() => InvokeRecievedEvent(recievedBytes, data));
        ListenForMessages();
    }
コード例 #2
0
 private void ListenForMessages()
 {
     try
     {
         BufferStateObject state = new BufferStateObject();
         _Connection.Client.BeginReceive(state.buffer, 0, state.buffer.Length, SocketFlags.None, RecieveMessage, state);
     }
     catch (SocketException sEx)
     {
         if (_Connection.Connected)
         {
             Task.Delay(500).ContinueWith(t => ListenForMessages());
         }
         else
         {
             Disconnected.Invoke(sEx.Message);
         }
     }
 }