Initializing and Connecting

[This is the first in a small series of posts covering some of the new/different parts of the client library compared to the version in the official SDK.  In this first installment we’ll cover Initializing and Connecting.]

I don’t use the SimConnect.cfg file with its index based selection of a set of connection parameters; for one, that just flat out wouldn’t work for a Silverlight application, and there are several other environments where that doesn’t work well.  So instead, I just take the server information directly via the Open() function.  You application is free to use whatever method it wants to query/store this information.

Here’s some prelim docs for the constructor, open, and close functions.

Constructor (Desktop version of client)

new SimConnect(object syncObject, bool bSerializePackets);

Where

syncObject

Synchronization object used to marshal the OnRecvXxx calls onto your applications UI thread.  This can be either a Window/Control for a WinForms app, or the Dispatcher object for a WPF app.  If this value is null, then the OnRecvXxx calls will be made on a background thread, and you will need to do any UI thread syncing where needed. 

Default value is null.

bSerializePackets

If true, the OnRecvXxx handlers will be serialized through a background thread provided by the client library.  If syncObject is non-null, the OnRecvXxx handlers will be UI thread synced from this background thread.  This ensures that the OnRecvXxx handlers are called in the same order the data was received from SimConnect.  Only one OnRecvXxx handler will be active at the same time

If false, the OnRecvXxx handlers are called directly from the IO Completion port handlers (OS/Framework provided background thread).  If syncObject is non-null, the OnRecvXxx handlers will be UI thread synced from this IO Completion port thread.  Multiple OnRecvXxx handlers can be active at the same time (and the same OnRecvXxx handler can be called a second time before the first instance has returned).  You will need to know your multi-threading and reentrant programming requirements when using this option with syncObject = null.  ** Note – this option hasn’t been extensively tested yet, so if you are trying it and things aren’t working, try chaning this back to true and see if that clears up the problem :->  **

Default value is true.

 

Constructor (SilverLight version of client)

new SimConnect(object syncObject);

Where

syncObject

Synchronization object used to marshal the OnRecvXxx calls onto your applications UI thread.  For SilverLight, this value must be a Dispatcher object.  Silverlight is much touchier about anything much running on a background thread (including updating data bound fields, which WPF is just fine with on a BG thread), so the Dispatcher object is required for SilverLight applications and all OnRecvXxx events will be UI thread sync’d, a null value for this field will throw an exception.

 

Open function (Desktop version of client)

Open a local connection using the default named pipe

void Open(string strAppName);

Where

strAppName

String name for your client application

 

Open a TCP/IP connection (IPv4 or IPv6)

void Open(string strAppName, string strHostName, Int32 iPort, Boolean bIsIPV6);

Where

strAppName

String name for your client application

strHostName 

String name for the server to connect to.  This can be either a machine name or the IP address as a dotted string “192.168.2.110”.  Passing either a null or an empty string for this parameter will default to localhost.

iPort

The port number to connect to.  Passing a 0 for this value will default to looking up the port number of the currently running local instance in the registry.  Only valid if passing null, empty string, “localhost”, or “127.0.0.1” as the strHostName parameter.

bIsIPV6 

Boolean value that selects between IPv4 (false) and IPv6 (true).

 

Open a TCP/IP connection (IPv4 only)

void Open(string strAppName, string strHostName, Int32 iPort);

Where

strAppName

String name for your client application

strHostName 

String name for the server to connect to.  This can be either a machine name or the IP address as a dotted string “192.168.2.110”.  Passing either a null or an empty string for this parameter will default to localhost.

iPort

The port number to connect to.  Passing a 0 for this value will default to looking up the port number of the currently running local instance in the registry.  Only valid if passing null, empty string, “localhost”, or “127.0.0.1” as the strHostName parameter.

 

Open a named pipe connection

void Open(string strAppName, string strHostName, string strPipeName);

Where

strAppName

String name for your client application

strHostName

String name for the server to connect to.  This can be either a machine name or the IP address as a dotted string “192.168.2.110”.  Passing a null or empty string will default to localhost.

strPipe

String name for the named pipe.  Passing a null or empty string will default to “Microsoft Flight Simulator\\SimConnect” (which works with both FSX and ESP).

 

Open function (SilverLight version of client)

Open a TCP/IP connection (IPv4 only)

void Open(string strAppName, string strHostName, Int32 iPort);

Where

strAppName

String name for your client application

strHostName 

String name for the server to connect to.  This can be either a machine name or the IP address as a dotted string “192.168.2.110”.  Passing either a null or an empty string for this parameter will default to localhost.

iPort

The port number to connect to.  Passing a 0 for this value will default to looking up the port number of the currently running local instance in the registry.  Only valid if passing null, empty string, “localhost”, or “127.0.0.1” as the strHostName parameter.

 

Close a connection

void Close();

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s