Loads the client configuration file.

Namespace: Sfs2X
Assembly: SmartFox2X (in SmartFox2X.dll) Version: 1.7.0.0 (1.7.0)

Syntax

C#
public void LoadConfig(
	string filePath,
	bool connectOnSuccess
)

Parameters

filePath
Type: System..::..String
(default: sfs-config.xml) Filename of the external XML configuration, including its path relative to the folder of the application file.
connectOnSuccess
Type: System..::..Boolean
(default: true) A flag indicating if the connection to SmartFoxServer must be attempted upon configuration loading completion.

Remarks

The SmartFox instance can be configured through an external xml configuration file loaded at run-time. By default, this method loads a file named "sfs-config.xml", placed in the same folder of the application file.
If the AutoConnect parameter is set to true, on loading completion the Connect(String, Int32) method is automatically called by the API, otherwise the CONFIG_LOAD_SUCCESS event is dispatched. In case of loading error, the CONFIG_LOAD_FAILURE event id fired.

The external xml configuration file has the following structure; ip, port and zone parameters are mandatory, all other parameters are optional.

 Copy imageCopy
<SmartFoxConfig>
    <host>127.0.0.1</host>
    <port>9933</port>
    <udpHost>127.0.0.1</udpHost>
    <udpPort>9933</udpPort>
    <zone>simpleChat</zone>
    <debug>true</debug>
    <httpPort>8080</httpPort>
    <httpsPort>8443</httpsPort>
    <useBlueBox>true</useBlueBox>
    <blueBoxPollingRate>750</blueBoxPollingRate>
</SmartFoxConfig>

Examples

The following example shows how to load an external configuration file:
 Copy imageCopy
void SomeMethod() {
    sfs.AddEventListener(SFSEvent.CONFIG_LOAD_SUCCESS, OnConfigLoadSuccessHandler);
    sfs.AddEventListener(SFSEvent.CONFIG_LOAD_FAILURE, OnConfigLoadFailureHandler);
    sfs.LoadConfig("testEnvironmentConfig.xml", false);
}
void OnConfigLoadSuccessHandler(BaseEvent evt) {
    Console.WriteLine("Config file loaded, now connecting...");
    sfs.Connect(sfs.IpAddress, sfs.Port);
}
void OnConfigLoadFailureHandler(BaseEvent evt) {
    Console.WriteLine("Failed loading config file: " + evt.Params["message"]);
}

See Also