private void InitClient() { Client = new ClientConnect(true); Client.SetOnReceiveEvent((c, m) => { LemonMessage msg = (LemonMessage)m; if (msg.StateCode == 0) { lock (ClientLock) { //Debug.Log("receive:" + msg.Body); Battle battle = (Battle)SerializeObject.DeserializeFromString(msg.Body, typeof(Battle)); ReceiveCommandObj.PostAsyncMethod(battle.Step.ToString(), battle); } } }); Client.OnErrorEvent = (c, e) => { //Debug.Log("出错了" + e.Message); }; Client.OnConnectEvent = (c) => { //Debug.Log("连接上了"); }; Client.OnDisconnectEvent = (c) => { //Debug.Log("连接断开了"); }; Client.Connect <LemonMessage>(IP, Port); }
public void InitClient() { Client = new ClientConnect(true); Client.SetOnReceiveEvent((c, m) => { LemonMessage msg = (LemonMessage)m; if (msg.StateCode == 0) { lock (ClientLock) { PokerBattle battle = (PokerBattle)SerializeObject.DeserializeFromString(msg.Body, typeof(PokerBattle)); //Debug.Log("接收到命令" + battle.Step); MsgList.Enqueue(battle); } } }); Client.OnErrorEvent = (c, e) => { //Debug.Log("出错了" + e.Message); }; Client.OnConnectEvent = (c) => { //Debug.Log("连接上了"); }; Client.OnDisconnectEvent = (c) => { //Debug.Log("连接断开了"); }; Client.Connect <LemonMessage>(IP, Port); }
private void SendToClient(BattleCommand command, string askAccountID = null) { Battle.Step = command; Battle.LibraryCardNum = CardLibrary.Count; string battleStr = JsonSerialize.SerializeToString(Battle); Battle newBattle = (Battle)JsonSerialize.DeserializeFromString(battleStr, typeof(Battle)); Record.Add(newBattle); Countdown.SetCommand(command); ToCleintCommand.SendToClient(command, Battle, askAccountID); }