Ejemplo n.º 1
0
        public void Send(string actorType, string actorName, byte[] data, int offset, int count)
        {
            var actorKey = ActorIdentity.GetKey(actorType, actorName);

            if (_remoteActor == null)
            {
                throw new InvalidOperationException(
                          string.Format("The remote actor has not been connected, Type[{0}], Name[{1}].", actorType, actorName));
            }
            if (_remoteActor.GetKey() != actorKey)
            {
                throw new InvalidOperationException(
                          string.Format("Remote actor key not matched, [{0}]:[{1}].", _remoteActor.GetKey(), actorKey));
            }

            _innerSession.Send(data, offset, count);
            _keepAliveTracker.OnDataSent();
        }
Ejemplo 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));
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void SendTo(string sessionKey, byte[] data, int offset, int count)
        {
            if (!IsListening)
            {
                throw new InvalidOperationException("The server has stopped to listen.");
            }

            ActorTransportSession session = null;

            if (_sessions.TryGetValue(sessionKey, out session))
            {
                session.Send(data, offset, count);
            }
            else
            {
                _log.WarnFormat("SendTo, cannot find target session [{0}].", sessionKey);
            }
        }