Exemple #1
0
        private void TcpServer_ClientReceiveData(AsyncUserToken userToken, byte[] data)
        {
            if (!shareDesktop)
            {
                return;
            }
            bool isExist = false;

            lock (rdViewers)
            {
                if (rdViewers.ContainsKey(userToken.Identifier))
                {
                    isExist = true;
                }
            }
            if (!isExist)
            {
                ResMsg rm = Authentication(data);
                if (rm.Result)
                {
                    ThreadPool.UnsafeQueueUserWorkItem(new WaitCallback(state =>
                    {
                        AsyncUserToken asyncUserToken = (AsyncUserToken)state;
                        asyncUserToken.SendData(Encoding.ASCII.GetBytes("login ok!"));
                    }), userToken);
                    RDViewer viewer = new RDViewer()
                    {
                        UserName  = rm.Message,
                        UserToken = userToken
                    };
                    lock (rdViewers)
                    {
                        rdViewers.Add(userToken.Identifier, viewer);
                    }
                    ShowLog(viewer.UserName + "开始观看,来源:" + userToken.Identifier);
                }
            }
            else
            {
                lock (recvBuffer)
                {
                    recvBuffer.AddRange(data);
                }
            }
        }
Exemple #2
0
        private void TcpServer_ClientDisConnected(object sender, AsyncUserToken e)
        {
            RDViewer viewer = null;

            lock (rdViewers)
            {
                if (rdViewers.ContainsKey(e.Identifier))
                {
                    viewer = rdViewers[e.Identifier];
                    rdViewers.Remove(e.Identifier);
                }
            }
            if (viewer != null)
            {
                viewer.UserToken = null;
                ShowLog(viewer.UserName + "停止观看");
            }
        }
Exemple #3
0
 private void SendResult(string result)
 {
     //Bson打包
     byte[] bs = PackBosn(result);
     //7E打包
     bs = Pack7E(bs);
     RDViewer[] viewers = null;
     lock (rdViewers)
     {
         viewers = new RDViewer[rdViewers.Count];
         rdViewers.Values.CopyTo(viewers, 0);
     }
     for (int i = 0; i < viewers.Length; i++)
     {
         if (viewers[i].UserToken != null)
         {
             viewers[i].UserToken.SendData(bs);
         }
     }
 }
Exemple #4
0
        /// <summary>
        /// 分享桌面线程
        /// </summary>
        private void ShareDesktop()
        {
            RDViewer[] viewers = null;
            while (shareDesktop)
            {
                if (rdViewers.Count == 0)
                {
                    Thread.Sleep(20);
                    continue;
                }

                try
                {
                    MemoryStream ms = new MemoryStream();
                    //获取屏幕截图并按质量压缩图片,然后将图片保存到内存流
                    CompressImage(GetScreen(), (long)nud_ImageQuality.Value, ms);
                    //gzip压缩字节流
                    byte[] bs = Compress(ms.ToArray());
                    //Bson打包
                    bs = PackBosn(bs);
                    //7E打包
                    bs = Pack7E(bs);

                    lock (rdViewers)
                    {
                        viewers = new RDViewer[rdViewers.Count];
                        rdViewers.Values.CopyTo(viewers, 0);
                    }
                    for (int i = 0; i < viewers.Length; i++)
                    {
                        if (viewers[i].UserToken != null)
                        {
                            viewers[i].UserToken.SendData(bs);
                        }
                    }
                }
                catch { }
                Thread.Sleep(50);
            }
        }