Jump to content
The simFlight Network Forums

Reconnect to FSUIPC


Recommended Posts

Hello Peter,

I have been using your .NET DLL sample (1.3) for C# and I was wondering how can it be coded so that if for some reason the application loses the connection to FSUIPC, it can reopen a new connection and continue functioning as if nothing happened?

            catch (FSUIPCException ex)
            {
                if (ex.FSUIPCErrorCode == FSUIPCError.FSUIPC_ERR_SENDMSG)
                {
                    // Send message error - connection to FSUIPC lost.
                    // Show message, disable the main timer loop and relight the 
                    // connection button:
                    // Also Close the broken connection.
                    FSUIPCConnection.Close();
                    MessageBox.Show("The connection to Flight Sim has been lost.", AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    // not the disonnect error so some other baddness occured.
                    // just rethrow to halt the application
                    throw ex;
                }
            }

The code above is the catch that detects when the connection is lost. How can I edit it, so that it just attempts to open a new connection and continue functioning normally?

Thanks for any help...

Link to comment
Share on other sites

Hello Peter,

I have been using your .NET DLL sample (1.3) for C#

Not mine. I'm afraid I don't know C# at all. It doesn't look anything like C or C++, and I don't like "managed" languages at all, too much stuff between me and what I want to do.

The code above is the catch that detects when the connection is lost. How can I edit it, so that it just attempts to open a new connection and continue functioning normally?

Can't you just try opening again?

The C code I supply (the source for the library) actually does lots of retries in any case, over a period of many seconds. Of course you don't want to hang the PC -- if you take the processor then FSUIPC, running in a different process, won't be getting time to respond and connect in any case. It is only a Message it is looking for, but you have to allow time for that.

So, the normal way would be to continue to attempt to connect on some sort of Timer message from Windows, sleeping (relinquishing the processor) in-between times. You could display a little amodal dialogue saying "trying to connect ..." with an "Abort" button too.

Regards

Pete

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.