示例#1
0
        private void OnMessage(object sender, MessageEventArgs e)
        {
                        #if SOCKET_IO_DEBUG
            debugMethod.Invoke("[SocketIO] Raw message: " + e.Data);
                        #endif
            Packet packet = decoder.Decode(e);

            switch (packet.enginePacketType)
            {
            case EnginePacketType.OPEN:     HandleOpen(packet);             break;

            case EnginePacketType.CLOSE:    EmitEvent("close");             break;

            case EnginePacketType.PING:             HandlePing();                   break;

            case EnginePacketType.PONG:             HandlePong();                   break;

            case EnginePacketType.MESSAGE:  HandleMessage(packet);  break;
            }
        }
        void OnMessage(object sender, MessageEventArgs e)
        {
            var packet = decoder.Decode(e);

            Info("[SocketIO]OnMessage#Raw message: " + e.Data + " => " + packet.enginePacketType);
            switch (packet.enginePacketType)
            {
            case EnginePacketType.OPEN:
            {
                Info("    [SocketIO]OnMessage#open sid: " + packet.json["sid"].str);

                wsConnected = ws.IsConnected;
                //sid = packet.json["sid"].str;
                //RaiseEvent("open");
            }
            break;

            case EnginePacketType.CLOSE:
                wsConnected = ws.IsConnected;
                RaiseEvent("close");
                break;

            case EnginePacketType.PING:
                EmitPacket(new Packet(EnginePacketType.PONG));
                break;

            case EnginePacketType.PONG:
                RaiseEvent("pong");
                break;

            case EnginePacketType.MESSAGE:
                if (packet.json == null)
                {
                    Warning("  [SocketIO]null message");
                }
                else
                {
                    if (packet.socketPacketType == SocketPacketType.ACK)
                    {
                        Debug("  [SocketIO]ACK");
                        for (int i = 0; i < ackList.Count; i++)
                        {
                            if (ackList[i].packetId != packet.id)
                            {
                                continue;
                            }
                            lock (ackQueueLock) { ackQueue.Enqueue(packet); }
                        }
                    }
                    else if (packet.socketPacketType == SocketPacketType.EVENT)
                    {
                        Debug("  [SocketIO]Event");
                        try
                        {
                            var ioe = parser.Parse(packet.json);
                            EnqueueEvent(ioe);
                        }
                        catch (SocketIOException ex)
                        {
                            Error(ex);
                        }
                    }
                }
                break;

            default:
                Warning("    [SocketIO] unknown: " + packet.enginePacketType);
                break;
            }
        }