Esempio n. 1
0
        private void Socket_DataReceived(object sender, DataReceivedEventArgs e)
        {
            _logger.Trace("Received DataReceived event from socket");

            // check what socket type we have
            var socket = sender as TcpSocketWrapper;
            if (socket != null)
            {
                // let the base class handle fragments
                ProcessReceivedDataFragment(e.Data, (data, startIndex) =>
                {
                    // treat restored messages as data messages
                    var fragmentDataMessage = DataMessageFactory.CreateFromRawMessage(data, startIndex);
                    RaiseDataMessageReceivedEvent(fragmentDataMessage);
                });

                // start over
                socket.ReceiveAsync();
            }
            else
            {
                // udp
                var udpSocket = sender as UdpSocketWrapper;
                if (udpSocket != null)
                {
                    // udp does not fragment
                    var dataMessage = DataMessageFactory.CreateFromRawMessage(e.Data);
                    RaiseDataMessageReceivedEvent(dataMessage);

                    // start over
                    udpSocket.ReceiveFromAsync();
                }
            }
        }
Esempio n. 2
0
        private void Receiver_DataReceived(object sender, DataReceivedEventArgs e)
        {
            _logger.Trace("Received DataReceived event from receiving socket");

            // let the base class handle the fragments
            ProcessReceivedDataFragment(e.Data, (data, startIndex) =>
                                                    {
                                                        // treat restored messages as control commands
                                                        var command = ControlCommandFactory.CreateFromRawCommand(data, startIndex);
                                                        RaiseControlCommandReceivedEvent(command);
                                                    });

            // start over
            Socket.ReceiveAsync();
        }