Ejemplo n.º 1
0
 /// <summary>
 /// 心跳包监控
 /// </summary>
 /// <param name="obj"></param>
 async void DanmmuKeepAlive(CancellationToken token)
 {
     byte[] aliveMsg = DataToBytes("type@=mrkl/");
     await Task.Run(async() =>
     {
         while (true)
         {
             try
             {
                 if (token.IsCancellationRequested)
                 {
                     return;
                 }
                 AppLog.Info($"弹幕服务器【房间{ROOM_ID}】【发送心跳包】");
                 DanmuClient.Send(aliveMsg);
                 await Task.Delay(30000);
             }
             catch (Exception ex)
             {
                 //if (DanmuClient == null|| DanmuClient.ReadyState!= WebSocketState.Open)
                 //    return;
                 AppLog.Error("心跳异常", ex);
                 //if (!token.IsCancellationRequested)
                 //    Reconnect();
                 return;
             }
         }
     });
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 登录房间
        /// </summary>
        private void RoomLogin()
        {
            //string login = "******" + ROOM_ID + "/";
            string login = $"type@=loginreq/roomid@={ROOM_ID}/dfl@=sn@AA=105@ASss@AA=1/username@={username}/uid@={userid}/ver@=20190610/aver@=218101901/ct@=0/";

            byte[] loginBytes = DataToBytes(login);
            DanmuClient.Send(loginBytes);
            string joingroup = "type@=joingroup/rid@=" + ROOM_ID + "/gid@=-9999/";

            byte[] joingroupBytes = DataToBytes(joingroup);
            DanmuClient.Send(joingroupBytes);
            AppLog.Debug($"登录房间【{ROOM_ID}】成功");
        }