protected override void OnMessage(MessageEventArgs e) { //Loger.Debug(ID+ $"OnMessage{e.Data.Length}:" + e.Data); //Loger.Debug(LZString.Decompress(e.Data)); try { var Json_Data = LZString.DecompressFromUint8Array(e.RawData); var MsgBody = JObject.Parse(Json_Data); var id = MsgBody.GetValue("Id").Value <ushort>(); JObject data = MsgBody.GetValue("Data").Value <JObject>(); IWebSocketSession session; this.Sessions.TryGetSession(ID, out session); OneThreadSynchronizationContext.Instance.Post((obj) => { GameMainEntry.Instance.WebServerModule.Dispather.Dispatch(session, new MessageInfo_Json(id, data));//拉到主线程处理 }, null); } catch (Exception ex) { Loger.Error($"{ID} OnMessage:" + ex.ToString()); } base.OnMessage(e); }
public static byte[] Create_Msg_Json <T>(NetOpCode id, T msg) where T : IMessage { JObject msg_json = new JObject(); msg_json["Id"] = (ushort)id; msg_json["Data"] = JObject.FromObject(msg); var str_msg = JsonConvert.SerializeObject(msg_json); return(LZString.CompressToUint8Array(str_msg)); }
public static byte[] Create_Msg_Json(NetOpCode id, JObject data) { JObject msg_json = new JObject(); msg_json["Id"] = (ushort)id; msg_json["Data"] = data; var str_msg = JsonConvert.SerializeObject(msg_json); return(LZString.CompressToUint8Array(str_msg)); }