Exemplo n.º 1
0
        protected virtual void OnDataReceived(object sender, ActorTransportDataReceivedEventArgs e)
        {
            _keepAliveTracker.OnDataReceived();

            ActorFrameHeader actorKeepAliveRequestFrameHeader = null;
            bool             isHeaderDecoded = _channelConfiguration.FrameBuilder.TryDecodeFrameHeader(
                e.Data, e.DataOffset, e.DataLength,
                out actorKeepAliveRequestFrameHeader);

            if (isHeaderDecoded && actorKeepAliveRequestFrameHeader.OpCode == OpCode.Ping)
            {
                _log.DebugFormat("KeepAlive receive request from remote actor [{0}] to local actor [{1}].", _remoteActor, _localActor);

                var actorKeepAliveResponse       = new PongFrame();
                var actorKeepAliveResponseBuffer = _channelConfiguration.FrameBuilder.EncodeFrame(actorKeepAliveResponse);

                _log.DebugFormat("KeepAlive send response from local actor [{0}] to remote actor [{1}].", _localActor, _remoteActor);
                _connector.BeginSend(actorKeepAliveResponseBuffer);
            }
            else if (isHeaderDecoded && actorKeepAliveRequestFrameHeader.OpCode == OpCode.Pong)
            {
                _log.DebugFormat("KeepAlive receive response from remote actor [{0}] to local actor [{1}].", _remoteActor, _localActor);
                StopKeepAliveTimeoutTimer();
            }
            else
            {
                if (DataReceived != null)
                {
                    DataReceived(this, new ActorDataReceivedEventArgs(this.ConnectToEndPoint.ToString(), _remoteActor, e.Data, e.DataOffset, e.DataLength));
                }
            }
        }
Exemplo n.º 2
0
        public void OnDataReceived(object sender, byte[] data, int dataOffset, int dataLength)
        {
            if (!IsHandshaked)
            {
                Handshake(data, dataOffset, dataLength);
            }
            else
            {
                _keepAliveTracker.OnDataReceived();
                StopKeepAliveTimeoutTimer(); // intend to disable keep-alive timeout when receive anything

                ActorFrameHeader actorKeepAliveRequestFrameHeader = null;
                bool             isHeaderDecoded = _channelConfiguration.FrameBuilder.TryDecodeFrameHeader(
                    data, dataOffset, dataLength,
                    out actorKeepAliveRequestFrameHeader);
                if (isHeaderDecoded && actorKeepAliveRequestFrameHeader.OpCode == OpCode.Ping)
                {
                    _log.DebugFormat("KeepAlive receive request from remote actor [{0}] to local actor [{1}].", _remoteActor, _localActor);

                    var actorKeepAliveResponse       = new PongFrame();
                    var actorKeepAliveResponseBuffer = _channelConfiguration.FrameBuilder.EncodeFrame(actorKeepAliveResponse);

                    _log.DebugFormat("KeepAlive send response from local actor [{0}] to remote actor [{1}].", _localActor, _remoteActor);
                    _innerSession.Send(actorKeepAliveResponseBuffer);
                }
                else if (isHeaderDecoded && actorKeepAliveRequestFrameHeader.OpCode == OpCode.Pong)
                {
                    _log.DebugFormat("KeepAlive receive response from remote actor [{0}] to local actor [{1}].", _remoteActor, _localActor);
                    StopKeepAliveTimeoutTimer();
                }
                else
                {
                    if (SessionDataReceived != null)
                    {
                        SessionDataReceived(this, new ActorChannelSessionDataReceivedEventArgs(
                                                this, _remoteActor, data, dataOffset, dataLength));
                    }
                }
            }
        }