Beispiel #1
0
        /// <summary>
        /// Called from the currently operating Transport. Will pass forward to the Socket that has to call the callbacks.
        /// </summary>
        void IManager.OnPacket(Packet packet)
        {
            if (State == States.Closed)
            {
                HTTPManager.Logger.Information("SocketManager", "OnPacket - State == States.Closed");
                return;
            }

            switch (packet.TransportEvent)
            {
            case TransportEventTypes.Open:
                if (Handshake == null)
                {
                    Handshake = new HandshakeData();
                    if (!Handshake.Parse(packet.Payload))
                    {
                        HTTPManager.Logger.Warning("SocketManager", "Expected handshake data, but wasn't able to parse. Payload: " + packet.Payload);
                    }

                    (this as IManager).OnTransportConnected(Transport);

                    return;
                }
                else
                {
                    HTTPManager.Logger.Information("SocketManager", "OnPacket - Already received handshake data!");
                }
                break;

            case TransportEventTypes.Ping:
                if (this.Options.ServerVersion == SupportedSocketIOVersions.Unknown)
                {
                    HTTPManager.Logger.Information("SocketManager", "Received Ping packet from server, setting ServerVersion to v3!");
                    this.Options.ServerVersion = SupportedSocketIOVersions.v3;
                }

                lastPingReceived = DateTime.UtcNow;
                (this as IManager).SendPacket(new Packet(TransportEventTypes.Pong, SocketIOEventTypes.Unknown, "/", string.Empty));
                break;

            case TransportEventTypes.Pong:
                IsWaitingPong = false;
                break;
            }

            Socket socket = null;

            if (Namespaces.TryGetValue(packet.Namespace, out socket))
            {
                (socket as ISocket).OnPacket(packet);
            }
            else
            {
                HTTPManager.Logger.Warning("SocketManager", "Namespace \"" + packet.Namespace + "\" not found!");
            }
        }
        /// <summary>
        /// Called from the currently operating Transport. Will pass forward to the Socket that has to call the callbacks.
        /// </summary>
        void IManager.OnPacket(Packet packet)
        {
            if (State == States.Closed)
            {
                return;
            }

            switch (packet.TransportEvent)
            {
            case TransportEventTypes.Open:
                if (Handshake == null)
                {
                    Handshake = new HandshakeData();
                    if (!Handshake.Parse(packet.Payload))
                    {
                        HTTPManager.Logger.Warning("SocketManager", "Expected handshake data, but wasn't able to pars. Payload: " + packet.Payload);
                    }

                    (this as IManager).OnTransportConnected(Transport);

                    return;
                }
                break;

            case TransportEventTypes.Ping:
                (this as IManager).SendPacket(new Packet(TransportEventTypes.Pong, SocketIOEventTypes.Unknown, "/", string.Empty));
                break;

            case TransportEventTypes.Pong:
                IsWaitingPong = false;
                break;
            }

            Socket socket = null;

            if (Namespaces.TryGetValue(packet.Namespace, out socket))
            {
                (socket as ISocket).OnPacket(packet);
            }
            else
            {
                HTTPManager.Logger.Warning("SocketManager", "Namespace \"" + packet.Namespace + "\" not found!");
            }
        }