Inheritance: IDisposable
示例#1
0
        public AChannel ConnectChannel(string host, int port)
        {
            AChannel channel = this.service.GetChannel(host, port);

            channel.ConnectAsync();
            return(channel);
        }
示例#2
0
        private void UpdateChannel(AChannel channel)
        {
            if (channel.Id == 0)
            {
                return;
            }

            while (true)
            {
                byte[] messageBytes = channel.Recv();
                if (messageBytes == null)
                {
                    return;
                }

                if (messageBytes.Length < 6)
                {
                    continue;
                }

                Opcode opcode = (Opcode)BitConverter.ToUInt16(messageBytes, 0);
                try
                {
                    this.Run(opcode, messageBytes);
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                }
            }
        }
示例#3
0
        public bool IsChannelConnected(NetChannelType channelType)
        {
            AChannel channel = GetChannel(channelType);

            if (channel == null)
            {
                return(false);
            }
            return(true);
        }
示例#4
0
        public void RemoveChannel(long channelId)
        {
            AChannel channel = this.service?.GetChannel(channelId);

            if (channel == null)
            {
                return;
            }
            this.service.Remove(channelId);
            channel.Dispose();
        }
示例#5
0
        public void Close(NetChannelType channelType)
        {
            AChannel channel = this.GetChannel(channelType);

            if (channel == null || channel.Id == 0)
            {
                return;
            }
            this.channels.Remove(channelType);
            channel.Dispose();
        }
示例#6
0
        private void Send(object message, uint rpcId)
        {
            Opcode opcode = EnumHelper.FromString <Opcode>(message.GetType().Name);

            byte[] opcodeBytes  = BitConverter.GetBytes((ushort)opcode);
            byte[] seqBytes     = BitConverter.GetBytes(rpcId);
            byte[] messageBytes = MongoHelper.ToBson(message);

            NetChannelType channelType;

            if ((ushort)opcode > 7000 && (ushort)opcode < 8000)
            {
                channelType = NetChannelType.Login;
            }
            else if ((ushort)opcode > 0 && (ushort)opcode <= 1000)
            {
                channelType = NetChannelType.Battle;
            }
            else
            {
                channelType = NetChannelType.Gate;
            }

            AChannel channel = this.GetChannel(channelType);

            if (channel == null)
            {
                throw new GameException("game channel not found!");
            }

            channel.Send(new List <byte[]> {
                opcodeBytes, seqBytes, messageBytes
            });

            if (OpcodeHelper.IsNeedDebugLogMessage(opcode))
            {
                Log.Debug(MongoHelper.ToJson(message));
            }
        }
示例#7
0
        public AChannel GetChannel(long channelId)
        {
            AChannel channel = this.service?.GetChannel(channelId);

            return(channel);
        }
示例#8
0
 protected void OnError(AChannel channel, SocketError e)
 {
     this.errorCallback(channel, e);
 }
示例#9
0
		protected void OnError(AChannel channel, SocketError e)
		{
			this.errorCallback(channel, e);
		}
示例#10
0
        public void Connect(NetChannelType channelType, string host, int port)
        {
            AChannel channel = Share.Scene.GetComponent <NetworkComponent>().ConnectChannel(host, port);

            this.channels[channelType] = channel;
        }