Пример #1
0
        /// <summary>
        /// The main routine in which a connection is made and maintained.
        /// This function will only return once the EventLoop is stopped,
        /// which happens when the connection ends.
        /// </summary>
        public void Run()
        {
            try
            {
                // Keep these SDK objects available all the time the session is running.
                Viewer      = new Viewer();
                FrameBuffer = new FrameBuffer(Viewer);

                SetUpCallbacks(Viewer);

                // Begin the connection to the Server.

                if (CurrentCanvasSize == null)
                {
                    CurrentCanvasSize = new Vector2Int(1920, 1080);
                }

                UpdateFrameBufferToCanvasSize();

                // Make a Direct TCP connecticon.
                NewStatus($"Connecting to host address: {TcpAddress} port: {TcpPort}");
                using (DirectTcpConnector tcpConnector = new DirectTcpConnector())
                {
                    tcpConnector.Connect(TcpAddress, TcpPort, Viewer.GetConnectionHandler());
                }

                // Run the SDK's event loop.  This will return when any thread
                // calls EventLoop.Stop(), allowing this ViewerSession to stop.
                RunningSession = this;
                EventLoop.Run();
            }
            catch (Exception e)
            {
                Console.WriteLine("SDK error: {0}: {1}", e.GetType().Name, e.Message);

                // Handle the implied disconnect (or failed to connect) and show the exception message as a status
                DisconnectReason = e.GetType().Name + ": " + e.Message;
            }
            finally
            {
                RunningSession = null;

                // Dispose of the SDK objects.
                FrameBuffer?.Dispose();
                FrameBuffer = null;

                // If the viewer is still connected, this drops the connection.
                Viewer?.Dispose();
                Viewer = null;

                // Notify that the session is finished and another may be enqueued.
                ReportDisconnection();
            }
        }
Пример #2
0
        private void OnDisconnect(string disconnectMessage = null)
        {
            // This method is called at the end of every viewer session.
            session = null;

            if (string.IsNullOrEmpty(disconnectMessage))
            {
                disconnectMessage = "Disconnected";
            }

            Debug.Log(disconnectMessage);
        }
Пример #3
0
        private void StartConnection()
        {
            VncViewerSession viewerSession;

            try
            {
                Debug.Log("Connecting...");

                // Now start the connection
                viewerSession = new VncViewerSession
                {
                    TcpAddress = "192.168.2.133",
                    TcpPort    = 5900,

                    FrameBufferHandler = GetComponent <FrameBufferHandler>(),

                    OnConnect    = () => Debug.Log("Connected"),
                    OnDisconnect = (msg, flags) => OnDisconnect(msg),

                    // Put status messages on the status-label
                    OnNewStatus = (msg) => Debug.Log(msg),

                    CurrentCanvasSize = new Vector2Int(2560, 1440)
                };
            }

            catch (Exception ex)
            {
                OnDisconnect(ex.Message);
                return;
            }

            // Start this viewer session on the library thread.
            vncLibraryThread.StartViewerSession(viewerSession);
            session = viewerSession;
        }
Пример #4
0
 /// <summary>
 /// Starts the viewer session. Not safe to call again until the caller
 /// has been notified that the session has ended.
 /// </summary>
 /// <param name="viewerSession">The viewer session to start.</param>
 public void StartViewerSession(VncViewerSession viewerSession)
 {
     CurrentVncViewerSession = viewerSession;
     NewSession.Set();
 }