示例#1
0
文件: Gateway.cs 项目: HclX/HomeLink
        public void HandleMessage(Packet packet)
        {
            switch (packet.Type)
            {
                case PacketType.Register:
                    OnRegister(packet as RegisterPacket);
                    break;

                case PacketType.SensorMessage:
                case PacketType.SensorRegister:
                    OnSensorMessage(packet as SensorMessagePacket);
                    break;

                case PacketType.Acknowledge:
                    OnAcknowledge(packet as AcknowledgePacket);
                    break;

                case PacketType.Status:
                    OnStatusReport(packet as StatusReportPacket);
                    break;

                default:
                    break;
            }
        }
示例#2
0
文件: Proxy.cs 项目: HclX/HomeLink
        private void RegisterGateway(Packet packet, IWebSocketConnection socket)
        {
            if (packet.Type != PacketType.Register)
            {
                Utils.Log("Unexpected packet:{0}", packet);
                return;
            }

            Gateway c = null;
            RegisterPacket rp = packet as RegisterPacket;

            if (!_allClients.TryGetValue(rp.GatewayId, out c))
            {
                c = new Gateway(rp.GatewayId, rp.GatewayAddr, rp.NetworkKey, socket);
                _allClients.Add(rp.GatewayId, c);
            }
            else
            {
                c.SetConnection(socket);
            }

            socket.OnMessage = (message) =>
            {
                onClientMessage(socket, message, c);
            };

            socket.OnBinary = (message) =>
            {
                onClientMessage(socket, message, c);
            };

            socket.OnClose = () =>
            {
                onClientDisconnected(socket, c);
            };

            c.HandleMessage(packet);
        }
示例#3
0
文件: Gateway.cs 项目: HclX/HomeLink
 private void AckPacket(Packet packet)
 {
     AcknowledgePacket ack = new AcknowledgePacket(packet.Id);
     Socket.Send(ack.ToBytes());
 }