Beispiel #1
0
 /// <summary>
 /// 定义一个client  每间隔10秒发送一次心跳,然后10分钟发送一次状态消息,借还购线等操作日志则马上传输
 /// </summary>
 public void protobuf_checklink()
 {
     while (true)
     {
         string str = "";
         try
         {
             if (bLoginFlag)//首先检测是否在线
             {
                 LaidianCommandModel.Builder laidianCommand = LaidianCommandModel.CreateBuilder();
                 laidianCommand.SetMessageType(MessageType.HEARTBEAT);
                 sendMessage(client, laidianCommand.Build());
                 Thread.Sleep(500);
             }
             else
             {
                 //连接服务器
                 client.Connect();
             }
         }
         catch (IOException ex)//远程连接已经关闭
         {
         }
         catch (Exception sd)
         {
             str = sd.Message;
             Console.WriteLine(str);
         }
         Thread.Sleep(3000);
     }
 }
Beispiel #2
0
        /// <summary>
        /// 如果连接上去,则发送登陆指令。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Client_Connected(object sender, EventArgs e)
        {
            LaidianCommandModel.Builder loginbuilder = LaidianCommandModel.CreateBuilder();
            loginbuilder.SetMessageType(MessageType.LOGIN_REQ);
            LaidianCommandModel logincmd = loginbuilder.Build();

            sendMessage(client, logincmd);
        }