Exemple #1
0
        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;
            }
        }
Exemple #2
0
        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);
        }
Exemple #3
0
 private void AckPacket(Packet packet)
 {
     AcknowledgePacket ack = new AcknowledgePacket(packet.Id);
     Socket.Send(ack.ToBytes());
 }