Click or drag to resize

SmartFoxLoadConfig Method (String, Boolean)

Loads the client configuration file.

Namespace:  Sfs2X
Assembly:  SmartFox2X (in SmartFox2X.dll) Version: 1.8.0.0 (1.8.0)
Syntax
C#
public void LoadConfig(
	string filePath,
	bool connectOnSuccess
)

Parameters

filePath
Type: SystemString
(default: sfs-config.xml) Filename of the external XML configuration, including its path relative to the folder of the application file.
connectOnSuccess
Type: SystemBoolean
(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 connectOnSuccess 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:

<SmartFoxConfig>

    <!-- required -->
    <host>localhost</host>

    <!-- required -->
    <port>9933</port>

    <udpHost>localhost</udpHost>
    <udpPort>9933</udpPort>

    <zone>BasicExamples</zone>
    <debug>true</debug>

    <httpPort>8080</httpPort>
    <httpsPort>8443</httpsPort>

    <blueBox>
        <isActive>true</isActive>
        <useHttps>false</useHttps>
        <pollingRate>500</pollingRate>

        <proxy>
            <host></host>
            <port></port>
            <userName></userName>
            <password></password>
            <bypassLocal>true</bypassLocal>
        </proxy>
    </blueBox>    
</SmartFoxConfig>
Examples
The following example shows how to load an external configuration file:
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