Пример #1
0
 /// <summary>
 /// 回复侦测
 /// </summary>
 /// <param name="data"></param>
 /// <param name="rsp"></param>
 private void RspDetect(byte[] data, SocketRsp rsp)
 {
     if (rsp.Rsp != null)
     {
         rsp.Rsp.Send(rspConst);
     }
     else
     {
         uDP.Send(rsp.Address, rsp.Port, rspConst);
     }
 }
Пример #2
0
        private void UDP_UDPCall(object sender, byte[] data, SocketRsp rsp)
        {
            string        topic;
            UDPSocketPack uDP = sender as UDPSocketPack;

            if (dicReqTopic.TryRemove(uDP, out topic))
            {
                var lst = DataPack.UnPackCopyRspTopic(data);

                SubscribeList.Subscribe.AddAddress(topic, lst.ToArray());

                dicReq.TryRemove(topic, out uDP);
                uDP.Close();
            }
        }
Пример #3
0
        /// <summary>
        /// 回复订阅信息
        /// </summary>
        /// <param name="data"></param>
        /// <param name="rsp"></param>
        private void RspSubscribe(byte[] data, SocketRsp rsp)
        {
            if (rsp.Rsp != null)
            {
                rsp.Rsp.Send(rspConst);
            }
            else
            {
                uDP.Send(rsp.Address, rsp.Port, rspConst);
            }
            //接收订阅
            var         msg     = DataPack.UnPackSubscribeMsg(data);
            AddressInfo address = new AddressInfo();

            address.Reset(msg.Address);
            SubscribeList.Subscribe.AddAddress(msg.TopicName, new AddressInfo[] { address });
            Console.WriteLine("接收订阅信息:" + msg.TopicName + "," + msg.Address);
        }
Пример #4
0
        /// <summary>
        /// 返回订阅地址
        /// </summary>
        /// <param name="data"></param>
        private void CopyAddress(byte[] data, SocketRsp rsp)
        {
            string topic = Encoding.Default.GetString(data, 1, data.Length - 1);
            var    addrs = SubscribeList.Subscribe.GetAddresses(topic);
            var    bytes = DataPack.PackCopyRspTopic(addrs);

            if (bytes == null)
            {
                bytes = Encoding.Default.GetBytes(" ");
            }
            if (rsp.Rsp != null)
            {
                rsp.Rsp.Send(bytes);
            }
            else
            {
                uDP.Send(rsp.Address, rsp.Port, bytes);
            }
        }
Пример #5
0
        private void Process(byte[] data, SocketRsp rsp)
        {
            switch (data[0])
            {
            case 2:
                CopyAddress(data, rsp);
                break;

            case 3:
                RspSubscribe(data, rsp);
                break;

            case 8:
                RspDetect(data, rsp);
                break;

            case 0:
                ProcessTopic(data);
                break;
            }
        }
Пример #6
0
 private void TcpServer_CallSrv(System.Buffers.ArrayPool <byte> pool, byte[] data, int len, SocketRsp rsp)
 {
     //接收组播信息
     NodeListener.Instance.Process(data, len);
     pool.Return(data);
 }
Пример #7
0
 private void UDP_UDPCall(object sender, byte[] data, SocketRsp rsp)
 {
     NodeListener.Instance.Process(data, data.Length);
 }
Пример #8
0
 private void Tcp_CallSrv(System.Buffers.ArrayPool <byte> pool, byte[] data, int len, SocketRsp rsp)
 {
     byte[] tmp = new byte[len];
     Array.Copy(data, 0, tmp, 0, tmp.Length);
     pool.Return(data);
     Process(tmp, rsp);
 }
Пример #9
0
 private void UDP_UDPCall1(object sender, byte[] data, SocketRsp rsp)
 {
     Process(data, rsp);
 }