Animatroller.ExpanderCommunication.ClientConnectionManager.Socket_DataReceived C# (CSharp) Method

Socket_DataReceived() private method

private Socket_DataReceived ( IAsyncResult result ) : void
result IAsyncResult
return void
        private void Socket_DataReceived(IAsyncResult result)
        {
            try
            {
                IPEndPoint remoteEP = null;
                byte[] received = this.socket.EndReceive(result, ref remoteEP);
                this.socket.BeginReceive(Socket_DataReceived, null);

                var msg = DeserializeInternalMessage(Encoding.UTF8.GetString(received));

                var aliveMessage = msg as Model.AliveMessage;
                if (aliveMessage != null)
                {
                    Debug.WriteLine("Alive from server");
                }

                var payloadMessage = msg as Model.PayloadMessage;
                if (payloadMessage != null)
                {
                    object payloadObject = DeserializePayload(payloadMessage.Payload);

                    try
                    {
                        this.payloadReceivedAction?.Invoke(payloadObject);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Exception while invoking callback with payload object " + ex.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error in Socket_DataReceivied " + ex.ToString());
            }
        }
    }