Ejemplo n.º 1
0
        private void _channel_Receive(object sender, Message <TSender> e)
        {
            if (!e.Data.Any())
            {
                return;
            }

            var id   = e.Data[0];
            var name = this._byteProtocol.GetProtocol(e.Sender, id);

            if (name == null)
            {
                if (id != 0)
                {
                    return;
                }
                if (e.Data.Length != ProtocolName.Length + 2)
                {
                    return;
                }
            }

            var data = ByteHelper.SkipByte(e.Data);

            if (name == null)
            {
                var m = ByteProtocolMessage.ParseMessage(data);
                if (m.Id != 0 || m.Name != ProtocolName)
                {
                    return;
                }
                name = ProtocolName;
            }

            ProtocolChannel <TSender> proto;

            lock (this._protocols) this._protocols.TryGetValue(name, out proto);
            proto?.OnReceive(new Message <TSender>(e.Sender, e.IsOwnMessage, data));
        }
Ejemplo n.º 2
0
 public void SetProtocol(byte protocolId, string protocolName)
 {
     this._channel.Send(ByteHelper.InsertByte(protocolId, Encoding.UTF8.GetBytes(protocolName)));
 }