Beispiel #1
0
 void HeartAsync()
 {
     TaskHelper.Start(() =>
     {
         try
         {
             while (true)
             {
                 if (_client.Connected)
                 {
                     if (Actived.AddMilliseconds(HeartSpan) <= DateTimeHelper.Now)
                     {
                         var sm = new BaseSocketProtocal()
                         {
                             BodyLength = 0,
                             Type       = (byte)SocketProtocalType.Heart
                         };
                         _client.SendAsync(sm.ToBytes());
                     }
                     ThreadHelper.Sleep(HeartSpan);
                 }
                 else
                 {
                     ThreadHelper.Sleep(1000);
                 }
             }
         }
         catch { }
     });
 }
Beispiel #2
0
        /// <summary>
        /// 基础发送数据
        /// </summary>
        /// <param name="protocalType"></param>
        /// <param name="data"></param>
        void BaseSend(ProtocalType protocalType, byte[] data)
        {
            var p = new BaseSocketProtocal();

            p.Type    = (byte)protocalType;
            p.Content = data;
            if (p.Content != null)
            {
                p.BodyLength = p.Content.Length;
            }
            else
            {
                p.BodyLength = 0;
            }
            _udpClient.SendAsync(p.ToBytes());
        }
Beispiel #3
0
        void BaseReply(string id, ProtocalType protocalType, byte[] data)
        {
            var p = new BaseSocketProtocal();

            p.Type    = (byte)protocalType;
            p.Content = data;
            if (p.Content != null)
            {
                p.BodyLength = p.Content.Length;
            }
            else
            {
                p.BodyLength = 0;
            }
            _udpServer.SendAsync(id, p.ToBytes());
        }
Beispiel #4
0
 /// <summary>
 /// SendAsync
 /// </summary>
 /// <param name="id"></param>
 /// <param name="baseSocketProtocal"></param>
 protected void SendAsync(string id, BaseSocketProtocal baseSocketProtocal)
 {
     _udpServer.SendAsync(id, baseSocketProtocal.ToBytes());
 }
Beispiel #5
0
 public void SendAsync(BaseSocketProtocal protocal)
 {
     _udpClient.SendAsync(protocal.ToBytes());
 }