Click or drag to resize

SmartFoxInitCrypto Method

Initializes the connection cryptography to protect all client-server communications with standard TLS protocol.

Namespace:  Sfs2X
Assembly:  SmartFox2X (in SmartFox2X.dll) Version: 1.8.0.0 (1.8.0)
Syntax
C#
public void InitCrypto()
Remarks
This method must be called right after a successful connection, before the login is performed.
Once the encryption initialization process is successfully completed, all of the server's data will be encrypted using standard AES 128-bit algorithm, with a secure key served over HTTPS.

IMPORTANT UNITY REMARKS

This method is not available when building for WebGL: use WSS connection instead.

When building for the Web Player, do not use Security.PrefetchSocketPolicy in your code. In fact this method accepts an IP address only, while you should connect to the domain name instead, since the SSL certificate is (typically) bound to that. Let the Web Player auto-fetch the cross-domain policy from the default TCP port 843. In order to do this, add a listener for such port in the SFS2X AdminTool's Server Configurator module.

Examples
The following example initializes the encrypted communication:
void SomeMethod() {
    SmartFox sfs = new SmartFox();

    sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
    sfs.AddEventListener(SFSEvent.CRYPTO_INIT, OnEncryptionInitialized);

    sfs.Connect("mysecuredomain.com", 9933);
}

void OnConnection(BaseEvent evt) {
    if ((bool)evt.Params["success"])
    {
        Console.WriteLine("Connection was established");

        // Initialize encrypted connection
        sfs.InitCrypto();
    }
    else
    {
        Console.WriteLine("Connection failed");
    }
}

void OnEncryptionInitialized(BaseEvent evt) {
    if ((bool)evt.Params["success"])
    {
        // Do login
        sfs.Send( new LoginRequest("FozzieTheBear", "", "SimpleChat") );
    }
    else
    {
        Console.WriteLine("Encryption initialization failed. Caused by: " + (string)evt.Params["errorMsg"]);
    }
}
See Also