Using the server as a COM component.


Using the server as a COM component.

Author
Message
supportingit
View Quick Profile

Supreme Being
Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)

Group: Forum Members
Last Active: 5 Years Ago
Posts: 4, Visits: 17
I'm constantly getting a failure every time I try to call AddClient(foo, bar);

I have wrapped it up in a class, in the hope of making things easier when I put it in to a windows service, but going by this, I may not bother.

Anyway, do you have any suggestions as to where I'm going wrong?

Anyway, I'm calling this class as follows from a WinForm at the moment...

Declare it.
private VNCServer _serverx;


Instantiate it.
Snippet
_serverx = new VNCServer();

And I have a button to initiate a reverse connection, its click event is...
Snippet
private void buttonRemoteVNC_Click(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new MethodInvoker(delegate()
                { this.buttonRemoteVNC_Click(sender, e); }));
            }
            else
            {
                _serverx.StartRemote(IPAddressPort);
            }
        }


And the class that sits behind it all is....



using
 System;
using System.Diagnostics;
using ServerX;

namespace Test_Client.Components
{
    public class VNCServer
    {
        private bool _AllowConnections// = axServerX.AllowConnections;
        private int _Port// = axServerX.Port;
        private int _IdleTimeout// = axServerX.IdleTimeout;
        private bool _ShowTrayIcon// = axServerX.ShowTrayIcon;
        private bool _QueryConnect// = axServerX.QueryConnect;
        private bool _RemoveWallpaper// = axServerX.RemoveWallpaper;
        private bool _RemoveBackgroundPattern// = axServerX.RemoveBackgroundPattern;
        private bool _PointerEvents// = axServerX.AcceptPointerEvents;
        private bool _KeyboardEvents// = axServerX.AcceptKeyEvents;
        private bool _AcceptCutText// = axServerX.AcceptCutText;
        private bool _SendCutText// = axServerX.SendCutText;
        private bool _DisableLocalInputs// = axServerX.DisableLocalInputs;

        private string _textPassword = "cherry";

        private ServerX.CSC_ServerXControl axServerX;

        #region <<Public properties>>
        private string _clientaddress;
        public string ClientAddress
        {
            get { return _clientaddress; }
            set { _clientaddress = value.Trim(); }
        }

        private ushort _port;
        public ushort Port
        {
            get { return _port; }
            set { _port = Convert.ToUInt16(value); }
        }

        private string _repeaterid;
        public string RepeaterID
        {
            get { return _repeaterid; }
            set { _repeaterid = value.Trim(); }
        }

        private ServerX.ConnectionProxyType _connectiontype;
        public ServerX.ConnectionProxyType ConnectionType
        {
            get { return _connectiontype; }
            set { _connectiontype = (ServerX.ConnectionProxyType)value; }
        }

        private string _proxyaddress;
        public string ProxyAddress
        {
            get { return _proxyaddress; }
            set { _proxyaddress = value.Trim(); }
        }

        private ushort _proxyport;
        public ushort ProxyPort
        {
            get { return _proxyport; }
            set { _proxyport = Convert.ToUInt16(value); }
        }

        private string _proxyuser;
        public string ProxyUser
        {
            get { return _proxyuser; }
            set { _proxyuser = value.Trim(); }
        }

        private string _proxypassword;
        public string ProxyPassword
        {
            get { return _proxypassword; }
            set { _proxypassword = value.Trim(); }
        }

        public bool AcceptingConnections
        {
            get { return axServerX.AllowConnections; }
        }
        #endregion

        /// <summary>
        /// Constructor
        /// </summary>
        public VNCServer()
        {
            axServerX = new CSC_ServerXControl();
            SetProperties();
            ConnectServerXEvents();
        }
        
        #region <<Methods to control the server>>
        /// <summary>
        /// Starts the server
        /// </summary>
        public void StartVNCServer()
        {

            try
            {
                axServerX.Start();
            }
            catch (Exception ex)
            {
                DesktopSpaces.Components.DSEventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error);
            }
        }

        /// <summary>
        /// Stops the server
        /// </summary>
        public void StopVNCServer()
        {
            axServerX.Stop();
        }

        /// <summary>
        /// Starts a reverse connection
        /// </summary>
        /// <param name="address">The address of the remote system running a listening VNC viewer</param>
        /// <param name="port">The port number the listening viewer is on</param>
        public void StartRemote(string address, ushort port)
        {

            try
            {
                axServerX.AddClient(address, Convert.ToUInt16(port));
            }
            catch (UnauthorizedAccessException)
            {
                //ignore it. the exception is raised by the canceled credentials dialog
            }
            catch (Exception ex)
            {
                DesktopSpaces.Components.DSEventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error);
            }
        }
        #endregion
        
        #region <<Methods to set ServerX properties>>
        private void SetProperties()
        {
           try
            {
               axServerX.AllowConnections = true;
               axServerX.Password = _textPassword;
               axServerX.Port = Convert.ToInt32(5900);
               axServerX.IdleTimeout = Convert.ToInt32(_IdleTimeout);
               axServerX.ShowTrayIcon = true;
               axServerX.QueryConnect = _QueryConnect;
               axServerX.RemoveWallpaper = true;
               axServerX.RemoveBackgroundPattern = true;
               axServerX.EnableUserInterfaceEffects = false;
               axServerX.AcceptPointerEvents = _PointerEvents;
               axServerX.AcceptKeyEvents = _KeyboardEvents;
               axServerX.AcceptCutText = _AcceptCutText;
               axServerX.SendCutText = _SendCutText;
               axServerX.DisableLocalInputs = _DisableLocalInputs;
            }
            catch (Exception ex)
            {
                DesktopSpaces.Components.DSEventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error);
            }
        }
        #endregion

        #region <<ServerX event stuff>>
        private void ConnectServerXEvents()
        {
            axServerX.Connected += new _ISc_ServerXEvents_ConnectedEventHandler(axServerX_Connected);
            axServerX.Disconnected += new _ISc_ServerXEvents_DisconnectedEventHandler(axServerX_Disconnected);
        }

        private void axServerX_Connected(string e)
        {
            DesktopSpaces.Components.DSEventLog.WriteEntry(String.Format("Client connected: {0}", e), EventLogEntryType.Information);
        }

        private void axServerX_Disconnected(string e)
        {
            DesktopSpaces.Components.DSEventLog.WriteEntry(String.Format("Client disconnected: {0}", e), EventLogEntryType.Information);
        }
        #endregion
    }
}


Yury Averkiev (s-code)
View Quick Profile

Supreme Being
Supreme Being (193.8K reputation)Supreme Being (193.8K reputation)Supreme Being (193.8K reputation)Supreme Being (193.8K reputation)Supreme Being (193.8K reputation)Supreme Being (193.8K reputation)Supreme Being (193.8K reputation)Supreme Being (193.8K reputation)Supreme Being (193.8K reputation)

Group: Administrators
Last Active: 3 days ago @ 6:45 PM
Posts: 1.9K, Visits: 3.5K
Hi,
after you've create ServerX instance you must add it to a form. From the source code it seem that you create and instance, initialize its properties but to not add it to the form. This would be the reason why you are having problems getting ServerX to work.

http://www.s-code.com/App_Themes/Default/images/blue_line.gif
Kindest Regards,
SmartCode Solutions Support
supportingit
View Quick Profile

Supreme Being
Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)

Group: Forum Members
Last Active: 5 Years Ago
Posts: 4, Visits: 17
Yes, that's right, I'm specifically wrapping it in a class so I do not have to add it to a form. Main reason is to add it to a wpf form, and the secondary reason is to add it to a windows service application.

I like to make components that I can reuse, and that was the idea behind wrapping it in a class. Wrapping the client in a user component to present a combined client view and toolbar has worked really well btw.

When I went through the forum before buying the components, it looked like that was possible, I'm guessing that its not?

Also, strangely, I instantiate the class in the forms onload event, which did not work, calling start would give me an error stating that the memory was corrupt, but by accidentally instantiating the class twice, that stopped happening, and calling start no longer produced an error, although it still does not kick into server mode.

Anyway, overall, I guess you are saying that its not going to work as a server component unless it is added to a form?
Yury Averkiev (s-code)
View Quick Profile

Supreme Being
Supreme Being (193.8K reputation)Supreme Being (193.8K reputation)Supreme Being (193.8K reputation)Supreme Being (193.8K reputation)Supreme Being (193.8K reputation)Supreme Being (193.8K reputation)Supreme Being (193.8K reputation)Supreme Being (193.8K reputation)Supreme Being (193.8K reputation)

Group: Administrators
Last Active: 3 days ago @ 6:45 PM
Posts: 1.9K, Visits: 3.5K
Anyway, overall, I guess you are saying that its not going to work as a server component unless it is added to a form?


Most likely. ServerX was never tested to work in a service anyway. The good news is that soon we will be releasing ServerX 2.0 which will work as a service. Unlike the current version, in the 2.0, when you register the COM object it will install a Windows service. The service will be deleted when COM object is unregistered.

If you purchased a license less than an year ago you will be able to upgrade to the v2.0 free of charge.

http://www.s-code.com/App_Themes/Default/images/blue_line.gif
Kindest Regards,
SmartCode Solutions Support
supportingit
View Quick Profile

Supreme Being
Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)Supreme Being (418 reputation)

Group: Forum Members
Last Active: 5 Years Ago
Posts: 4, Visits: 17
Support (s-code) (7/27/2010)
If you purchased a license less than an year ago you will be able to upgrade to the v2.0 free of charge.


Well, as it happens, I bought the components over a year ago, but I did take out a software maintenance renewal just a few weeks ago, so its all good.

I'm glad to hear the component is being worked on.

Cheers, Mark.
ningjih
View Quick Profile

Supreme Being
Supreme Being (1.6K reputation)Supreme Being (1.6K reputation)Supreme Being (1.6K reputation)Supreme Being (1.6K reputation)Supreme Being (1.6K reputation)Supreme Being (1.6K reputation)Supreme Being (1.6K reputation)Supreme Being (1.6K reputation)Supreme Being (1.6K reputation)

Group: Forum Members
Last Active: 7 Years Ago
Posts: 13, Visits: 24
When would you release the version 2 ?


Similar Topics


Reading This Topic