Click or drag to resize

SmartFoxConnect Method (String, Int32)

Establishes a connection between the client and a SmartFoxServer 2X instance.

Namespace:  Sfs2X
Assembly:  SmartFox2X (in SmartFox2X.dll) Version: (1.7.11)
public void Connect(
	string host,
	int port


Type: SystemString
The address of the server to connect to.
Type: SystemInt32
The TCP port to connect to.
ArgumentExceptionIf an invalid host/address or port is passed, and it can't be found in the loaded settings.
If no argument is passed, the client will use the settings loaded via LoadConfig(String, Boolean) method.

The client usually connects to a SmartFoxServer instance through a socket connection. In case a socket connection can't be established, and the UseBlueBox property is set to true, a tunnelled http connection through the BlueBox module is attempted as a fail-safe system. When a successful connection is established, the ConnectionMode property can be used to check the current connection mode.

Tunnelled http connection is not available in case of websocket connection.

When using a websocket connection to an IPv6 address, always wrap the host value in square brackets.

The following example connects to a local SmartFoxServer 2X instance:
void SomeMethod() {
    SmartFox sfs = new SmartFox();

    sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
    sfs.Connect("", 9933);

void OnConnection(BaseEvent evt) {
    if ((bool)evt.Params["success"])
        Console.WriteLine("Connection was established");                         // .Net / Unity
        System.Diagnostics.Debug.WriteLine("Connection was established");        // UWP
        Console.WriteLine("Connection failed");                         // .Net / Unity
        System.Diagnostics.Debug.WriteLine("Connection failed");        // UWP
See Also