ConnectionAccepted Event


http://www.s-code.com/forum/Topic2876.aspx
Print Topic | Close Window

By KarenS - Tuesday, January 05, 2010
Hi,

In my application I have used the ConnectEx method to establish a connection to my server.

I have added the Disconnected Event and the ConnectionAccepted Events.

In the Disconnected event method call I have called the ListenEx method on the port I am using.

In the ConnectionAccepted method call, i have called ConnectEx again to re-establish the connection and then StopListen().

I was expecting the Disconnected event method call to start listening for a reconnection to the server and then the control would fire the ConnectionAccepted event when the server recovers but the ConnectionAccepted event is never fired. Am I missing something or have I interepreted the events and methods supplied incorrectly?

Any help on this would be greatly appreciated,

Karen

By Yury Averkiev (s-code) - Tuesday, January 05, 2010
Hi Karen,
ConnectionAccepted gets fired when a listening ViewerX accepts incoming connection from a VNC server. So if you have received this event it means that connection from a VNC server has been accepted and VNC session is in progress.

The Connected event is fired when you establish connection via one of the ConnectXXX methods.

Please note that if you want ViewerX to be in listening mode after a connection was closed. You would have to call Listen/Ex method in the Disconnected event handler.

Please let me know if you need any additional assistance.

By KarenS - Tuesday, January 05, 2010
Hi,

I have included the basic format of my code below. If I start my application with the VNC Server running on the other PC then it connects fine. When I stop the server running on the other PC the disconnected event is fired. But after that when I restart the VNC Server on the other PC the ConnectionAccepted event is never fired. Any idea why this event is not fired?

Thanks, karen

public VNCPage ()

{

InitializeComponent();

viewerX.ConnectEx( "PCName", 5900, "hello" );

viewerX.Disconnected += new EventHandler( viewerX_Disconnected );

viewerX.ConnectionAccepted += new AxViewerX._ISmartCodeVNCViewerEvents_ConnectionAcceptedEventHandler( viewerX_ConnectionAccepted );

}

void viewerX_ConnectionAccepted( object sender, AxViewerX._ISmartCodeVNCViewerEvents_ConnectionAcceptedEvent e )

{

viewerX.ConnectEx( "PCName", 5900, "hello" );

viewerX.StopListen();

}

void viewerX_Disconnected ( object sender, EventArgs e )

{

viewerX.ListenEx( 5900 );

}

By Yury Averkiev (s-code) - Tuesday, January 05, 2010
1. usually it's a good idea to subscribe to the events before calling Connect/Listen methods. So you should subscribe first and then doing the connecting stuff.

2. void viewerX_ConnectionAccepted  part is comletely wrong. As I mentioned, when you receive ConnectionAccepted even it means that VNC connection has been established.

Basically the code is a bit mish mash, you are establishing a VNC connection via the Connect method and at the same time want to run a listening VNC viewer.
Are you trying to establish connection from ViewerX to VNC server or want to run ViewerX in a listening mode?

By KarenS - Tuesday, January 05, 2010
Hi,

Yes the code is a bit dodgy, it was a hack to try the control out. Smile

Can you post an example of how to get the ConnectionAccepted event to be fired? I have tried just listening and starting the VNC Server on the other PC and nothing happens. Sad

Thanks, Karen