Exemple #1
0
 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);
 }
Exemple #2
0
 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);
 }
Exemple #3
0
        private void Initialization()
        {
            actions = new Dictionary <CommandType, Func <AppOptions, int> >();
            actions.Add(CommandType.GetProcesses, GetProcesses);
            actions.Add(CommandType.Start, StartProcess);
            actions.Add(CommandType.Stop, StopProcess);
            actions.Add(CommandType.Restart, RestartProcess);

            client = new ClientConnect();
            client.Connect();
            client.CommandRecived += this.Client_CommandRecived;

            manualResetEvent = new ManualResetEvent(false);
            waitAnswer       = new ManualResetEvent(false);
        }
Exemple #4
0
 public void Start()
 {
     Client = new ClientConnect(true);
     Client.SetOnReceiveEvent((c, m) =>
     {
         LemonMessage msg = (LemonMessage)m;
         if (msg.StateCode == 0)
         {
             Battle battle = (Battle) new JsonSerialize().DeserializeFromString(msg.Body, typeof(Battle));
             //ReceiveCommandObj.PostAsyncMethod(battle.Step.ToString(), battle);
         }
     });
     Client.OnErrorEvent = (c, e) =>
     {
     };
     Client.OnConnectEvent = (c) =>
     {
     };
     Client.Connect <LemonMessage>(IP, Port);
 }
Exemple #5
0
        public async void TestLongSpeed()
        {
            ClientConnect client = new ClientConnect(true);
            await client.Connect <Msg>("60.205.210.198", 4120);

            client.OnConnectEvent = c =>
            {
                Console.WriteLine("连接到服务器上了");
            };
            client.OnDisconnectEvent = c =>
            {
                Console.WriteLine("连接断开了");
            };

            client.OnReceiveEvent = (c, m) =>
            {
                Console.WriteLine("receive:" + m.ToBytes().ToHexString());
                //c.SendMessage(Msg.GetOpenLampBackMsg("22180117000000".ToHexByte()));
            };
        }
Exemple #6
0
        public async Task <T> Request <T>(string command, params object[] pars)
        {
            ClientConnect client = new ClientConnect(false);
            bool          ret    = await client.Connect <LemonMessage>(IP, Port);

            if (!ret)
            {
                throw new Exception("网络连接失败");
            }
            string       sendParStr = ParameterConverter.PackParameter(command, SerializeObject, pars);
            LemonMessage message    = (LemonMessage)await client.SendAndBack(new LemonMessage()
            {
                Body = sendParStr
            });

            if (message == null)
            {
                return(default(T));
            }
            return(ParameterConverter.UnpackOneParameter <T>(message.Body, SerializeObject));
        }