예제 #1
0
파일: Proxy.cs 프로젝트: HclX/HomeLink
 private void onClientDisconnected(IWebSocketConnection socket, Gateway client)
 {
     if (client == null)
     {
         _unregisteredConnections.Remove(socket);
     }
     else
     {
         DisconnectClient(client);
     }
 }
예제 #2
0
파일: Proxy.cs 프로젝트: HclX/HomeLink
        private void onClientMessage(IWebSocketConnection socket, byte[] message, Gateway gateway)
        {
            Utils.Log("Incoming binary message:{0}", BitConverter.ToString(message).Replace("-", ""));
            try
            {
                Packet packet = Packet.FromBytes(message);
                Utils.Log("{0}", packet);

                if (gateway == null)
                {
                    RegisterGateway(packet, socket);
                }
                else
                {
                    gateway.HandleMessage(packet);
                }
            }
            catch (BadPacketException)
            {
                Utils.Log("Failed to parse incoming packet");
            }
        }
예제 #3
0
파일: Proxy.cs 프로젝트: HclX/HomeLink
 private void onClientMessage(IWebSocketConnection socket, string message, Gateway gateway)
 {
     Utils.Log("Incoming text message:{0}", message);
     try
     {
         byte[] data = Convert.FromBase64String(message);
         onClientMessage(socket, data, gateway);
     }
     catch (FormatException)
     {
         Utils.Log("Base64 string decoding failed:{0}", message);
     }
 }
예제 #4
0
파일: Proxy.cs 프로젝트: HclX/HomeLink
 private void DisconnectClient(Gateway c)
 {
     c.Close();
     _allClients.Remove(c.Id);
 }
예제 #5
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);
        }