示例#1
0
        void OnUDPReceived(string endPointIp, byte[] data, int size)
        {
            int head = 0;

            while (head < size)
            {
                BytePacker packer   = new BytePacker(data);
                short      datasize = packer.ReadShort();
#if DISABLE_CHANNEL_VARINT
                short channelId = packer.ReadShort();
#else
                int   s         = 0;
                short channelId = VarintBitConverter.ToShort(packer, out s);
#endif

                if (channelId == (short)PreservedChannelId.Beacon)
                {
                }
                else if (channelId == (short)PreservedChannelId.Health)
                {
                    if (nodeMap.ContainsKey(endPointIp))
                    {
                        ComNode node = nodeMap[endPointIp];
                        node.HealthLostCount = 0;
                    }
                }
                else if (!dataChannelMap.ContainsKey(channelId))
                {
                }
                else
                {
                    IDataChannel channel = dataChannelMap[channelId];

                    if (channel.CheckMode == CheckMode.Sequre)
                    {
                        if (nodeMap.ContainsKey(endPointIp))
                        {
                            ComNode node = nodeMap[endPointIp];

                            node.HealthLostCount = 0;

                            object container = channel.FromStream(ref packer);

                            channel.Received(node, container);
                        }
                    }
                    else
                    {
                        object container = channel.FromStream(ref packer);

                        channel.Received(null, container);
                    }
                }

                head += datasize + 4;
            }
        }
示例#2
0
        void OnTCPReceived(string endPointIp, short channelId, byte[] data, int size)
        {
            if (channelId == (short)PreservedChannelId.Beacon)
            {
            }
            else if (channelId == (short)PreservedChannelId.Health)
            {
                if (serverNode == null)
                {
                    ;
                }
                if (endPointIp == serverNode.IP)
                {
                    healthLostCount = 0;
                }
            }
            else if (!dataChannelMap.ContainsKey(channelId))
            {
            }
            else
            {
                BytePacker   packer  = new BytePacker(data);
                IDataChannel channel = dataChannelMap[channelId];

                if (channel.CheckMode == CheckMode.Sequre)
                {
                    if (serverNode == null)
                    {
                        ;
                    }
                    if (endPointIp == serverNode.IP)
                    {
                        healthLostCount = 0;

                        object container = channel.FromStream(ref packer);

                        channel.Received(serverNode, container);
                    }
                }
                else
                {
                    healthLostCount = 0;

                    object container = channel.FromStream(ref packer);

                    channel.Received(null, container);
                }
            }
        }
示例#3
0
        void OnTCPReceived(string endPointIp, short channelId, byte[] data, int size)
        {
            if (channelId == (short)PreservedChannelId.Beacon)
            {
            }
            else if (channelId == (short)PreservedChannelId.Health)
            {
                if (nodeMap.ContainsKey(endPointIp))
                {
                    ComNode node = nodeMap[endPointIp];
                    node.HealthLostCount = 0;
                }
            }
            else if (!dataChannelMap.ContainsKey(channelId))
            {
            }
            else
            {
                BytePacker packer = new BytePacker(data);

                if (nodeMap.ContainsKey(endPointIp))
                {
                    ComNode node = nodeMap[endPointIp];

                    node.HealthLostCount = 0;

                    IDataChannel channel = dataChannelMap[channelId];

                    object container = channel.FromStream(ref packer);

                    channel.Received(node, container);
                }
            }
        }
示例#4
0
        void OnUDPReceived(string endPointIp, byte[] data, int size)
        {
            int head = 0;

            while (head < size)
            {
                BytePacker packer   = new BytePacker(data);
                short      datasize = packer.ReadShort();
#if DISABLE_CHANNEL_VARINT
                short channelId = packer.ReadShort();
#else
                int   s         = 0;
                short channelId = VarintBitConverter.ToInt16(packer, out s);
#endif

                if (channelId == (short)PreservedChannelId.Beacon)
                {
                    if (acceptBeacon && !isConnecting && !IsConnected)
                    {
                        string beaconData = (string)DataSerializer.Deserialize <string>(packer);

                        if (BeaconAccept(beaconData))
                        {
                            Connect(endPointIp);
                        }
                    }
                }
                else if (!dataChannelMap.ContainsKey(channelId))
                {
                }
                else
                {
                    if (serverNode == null)
                    {
                        break;
                    }
                    if (endPointIp == serverNode.IP)
                    {
                        healthLostCount = 0;

                        IDataChannel channel   = dataChannelMap[channelId];
                        object       container = channel.FromStream(ref packer);

                        channel.Received(serverNode, container);
                    }
                }

                head += datasize + 4;
            }
        }