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