Exemple #1
0
        private static void OnReceived(WebSocketSession session, string msg)
        {
            session.LastSendTime = DateTime.Now;

            if (!msg.Contains("cmd_id"))                                                                                            //验证消息格式
            {
                Log.Error("Miss main commond");
                return;
            }

            SocketData onRecevieData = JsonConvert.DeserializeObject <SocketData>(msg);             //接收数据

            if (onRecevieData.cmd_id != MainProtocol.MessageKeep)
            {
                Log.Info("Received Message:" + msg);
            }

            switch (onRecevieData.cmd_id)
            {
            case MainProtocol.MessageKeep:
                break;

            case MainProtocol.LoginCheckIn:
                Login.LoginCheckIn(session, onRecevieData);
                break;

            case MainProtocol.ReConnect:
                Login.Reconnect(session, onRecevieData);
                break;

            case MainProtocol.Broadcast:
                Chat.Broadcast(session, onRecevieData);
                break;

            default:
                break;
            }
        }