Example #1
0
        /// <summary>
        /// Connects to a VNC server with the specified hostname and port.
        /// </summary>
        /// <param name="hostname">The name of the host to connect to.</param>
        /// <param name="port">The port to connect on. 5900 is the usual for VNC.</param>
        /// <param name="options">Connection options, if any. You can specify a password here.</param>
        public void Connect(string hostname, int port = 5900, VncClientConnectOptions options = null)
        {
            Throw.If.Null(hostname, "hostname").Negative(port, "port");

            lock (this.c.SyncRoot)
            {
                var client = new TcpClient();

                try
                {
                    client.ConnectAsync(hostname, port).Wait();
                }
                catch (Exception)
                {
                    this.OnConnectionFailed();
                    throw;
                }

                try
                {
                    this.Connect(client.GetStream(), options);
                }
                catch (Exception)
                {
                    ((IDisposable)client).Dispose();
                    throw;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Connects to a VNC server.
        /// </summary>
        /// <param name="stream">The stream containing the connection.</param>
        /// <param name="options">Connection options, if any. You can specify a password here.</param>
        public void Connect(Stream stream, VncClientConnectOptions options = null)
        {
            Throw.If.Null(stream, "stream");


            lock (this.c.SyncRoot)
            {
                //SemicsVNC.Vnc.VncClient.
                //// 유저 데이터보내기
                string myId = UserID;
                byte[] buff = Encoding.Default.GetBytes(myId);
                stream.Write(buff, 0, buff.Length);

                //
                this.Close();

                this.options  = options ?? new VncClientConnectOptions();
                this.c.Stream = stream;

                try
                {
                    this.NegotiateVersion();
                    this.NegotiateSecurity();
                    this.NegotiateDesktop();
                    this.NegotiateEncodings();
                    this.InitFramebufferDecoder();

                    if (this.options.OnDemandMode)
                    {
                        this.IsConnected = true;
                    }
                    else
                    {
                        this.SendFramebufferUpdateRequest(false);
                        this.threadMain = new Thread(this.ThreadMain);
                        this.threadMain.IsBackground = true;
                        this.threadMain.Start();
                    }
                }
                catch (IOException e)
                {
                    this.OnConnectionFailed();
                    throw new VncException("IO error.", VncFailureReason.NetworkError, e);
                }
                catch (ObjectDisposedException e)
                {
                    this.OnConnectionFailed();
                    throw new VncException("Connection closed.", VncFailureReason.NetworkError, e);
                }
                catch (SocketException e)
                {
                    this.OnConnectionFailed();
                    throw new VncException("Connection failed.", VncFailureReason.NetworkError, e);
                }
            }
        }