Just a second...

Connecting through a load balancer

Connections between Diffusion™ clients and Diffusion servers can be routed through a load balancer. Some clients can pass additional information to a load balancer in the request path of their URL.

Supported in: JavaScript®, Apple®, Android™, C and Java™ APIs

An additional request path can be specified to define the connection URL context.

JavaScript
try {
    const session = await diffusion.connect({
        host : 'host_name',
        port : 'port',
        transports : 'transport',
        secure : false,
        path: 'path/diffusion'
    });

    // At this point we now have a connected session.
    console.log('Connected');
} catch(error) {
    console.error('Failed to create session!', error);
}
Java and Android
final Session session = Diffusion
    .sessions()
    .serverHost("host_name")
    .serverPort(port)
    .transports(transport)
    .secureTransport(false)
    .requestPath("/path/diffusion");
    .open();
                    
Apple
//  Copyright (C) 2021 Push Technology Ltd.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.

import Foundation
import Diffusion

class ConnectingLoadBalancer {

    func connect_disable_certificate_validation() {
        let host = "host"
        let additional_information_as_path = "path"

        // Formulate the URL string for connection via secure WebSocket,
        // appending the required 'diffusion` suffix
        let url_string = String(format: "wss://%@/%@/diffusion", host, additional_information_as_path)

        // Open the session, using the formulated URL.
        // Use the configuration to open a new session...
        PTDiffusionSession.open(with: URL(string: url_string)!) { (session, error) in

            // Check error is `nil`, then use session as required.
            // Ensure to maintain a strong reference to the session beyond the lifetime
            // of this callback, for example by assigning it to an instance variable.

            if (session == nil) {
                print("Failed to open session: %@", error!.localizedDescription)
                return
            }

            // At this point we now have a connected session.
            print("Connected.")
        }
    }

}

Specify a request path that begins with / and ends with /diffusion. The default value is /diffusion.

Load balancer configuration

Connections between Diffusion clients and Diffusion servers have specific requirements. If your load balancer handles Diffusion connections incorrectly, for example by routing subsequent client requests to different backend Diffusion servers, this can cause problems for your solution.

For more information about how to configure your load balancers to work with Diffusion, see Load balancers.