Exemplo n.º 1
0
        private void ConnectService(TcpClient tcpClient)
        {
            try
            {
                string loalIp = GetLocalIpAddress();

                IPEndPoint remotePoint = tcpClient.Client.RemoteEndPoint as IPEndPoint;
                IPEndPoint localpPoint = tcpClient.Client.LocalEndPoint as IPEndPoint;

                OnAddLogEvent($"VNC连接接入,客户端ip:{remotePoint.Address},端口:{remotePoint.Port}");

                VncServerSessionOptions options = new VncServerSessionOptions();
                //设置需要密码验证
                options.AuthenticationMethod = AuthenticationMethod.Password;

                // 创建一个会话
                VncServerSession session = new VncServerSession();
                session.MaxUpdateRate     = 20;
                session.Connected        += HandleConnected;
                session.ConnectionFailed += HandleConnectionFailed;
                session.Closed           += HandleClosed;
                session.PasswordProvided += HandlePasswordProvided;
                session.CreatingDesktop  += Session_CreatingDesktop;

                //session.FramebufferCapturing += Session_FramebufferCapturing;
                session.FramebufferUpdating += Session_FramebufferUpdating;

                session.KeyChanged             += Session_KeyChanged;
                session.PointerChanged         += Session_PointerChanged;
                session.RemoteClipboardChanged += Session_RemoteClipboardChanged;

                //设置分享的屏幕等信息 连接名字 name
                string name = loalIp + ":" + localpPoint.Port + "--" + remotePoint.Address + ":" + remotePoint.Port;
                VncScreenFramebufferSource vncScreenSource = new VncScreenFramebufferSource(name, Screen.PrimaryScreen);
                session.SetFramebufferSource(vncScreenSource);

                Dictionary <string, string> connectInfo = new Dictionary <string, string>()
                {
                    { "LoalIp", loalIp },
                    { "LocalpPort", localpPoint.Port.ToString() },
                    { "RemoteIp", remotePoint.Address.ToString() },
                    { "RemotePort", remotePoint.Port.ToString() },
                };
                session.UserData = connectInfo;
                session.Connect(tcpClient, options);

                sessionList.Add(session);
            }
            catch (Exception ex)
            {
                OnAddLogEvent($"连接出现错误,原因:{ex.Message}");
            }
        }
Exemplo n.º 2
0
        private void ConnectService(TcpClient tcpClient)
        {
            try
            {
                string loalIp = GetLocalIpAddress();

                IPEndPoint remotePoint = tcpClient.Client.RemoteEndPoint as IPEndPoint;
                Console.WriteLine($"VNC连接接入,客户端ip:{remotePoint.Address},端口:{remotePoint.Port}");

                VncServerSessionOptions options = new VncServerSessionOptions();
                //设置需要密码验证
                options.AuthenticationMethod = AuthenticationMethod.Password;

                // 创建一个会话
                VncServerSession session = new VncServerSession();

                session.Connected              += HandleConnected;
                session.ConnectionFailed       += HandleConnectionFailed;
                session.Closed                 += HandleClosed;
                session.PasswordProvided       += HandlePasswordProvided;
                session.CreatingDesktop        += Session_CreatingDesktop;
                session.KeyChanged             += Session_KeyChanged;
                session.PointerChanged         += Session_PointerChanged;
                session.RemoteClipboardChanged += Session_RemoteClipboardChanged;
                //设置分享的屏幕等信息 连接名字 name
                string name = loalIp + ":" + this.servicePort + "--" + remotePoint.Address + ":" + remotePoint.Port;
                VncScreenFramebufferSource vncScreenSource = new VncScreenFramebufferSource(name, Screen.PrimaryScreen);
                session.SetFramebufferSource(vncScreenSource);
                session.Connect(tcpClient, options);

                sessionList.Add(session);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"连接出现错误,原因:{ex.Message}");
            }
        }