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

Namespace: Sfs2X
Assembly: SmartFox2X (in SmartFox2X.dll) Version: (1.7.3)


public void Connect(
	string host,
	int port


Type: System..::..String
The address of the server to connect to.
Type: System..::..Int32
The TCP port to connect to.


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:
 Copy imageCopy
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");        // Windows Universal
        Console.WriteLine("Connection failed");                         // .Net / Unity
        System.Diagnostics.Debug.WriteLine("Connection failed");        // Windows Universal


System..::..ArgumentExceptionIf an invalid host/address or port is passed, and it can't be found in the loaded settings.

See Also