Connecting to Diffusion® Cloud

Before you can start interacting with Diffusion from your application, you must connect your client. This establishes a WebSocket (or long-polling HTTP) connection from your client application to Diffusion, over which all subsequent interactions are sent.

Credentials

To connect to Diffusion, you will need:

  • the hostname that you are connecting to

  • a principal (username) and password to authenticate your connection.

If you haven’t setup any credentials yet, you can in the Security tab of your service on the Dashboard.

For self-hosted installations, the default credentials are admin/passsword.

See User Authentication for more details on client authentication.

Connecting

When you connect to Diffusion, the SDK will provide a session object. If a connection is lost (due to bad network conditions or application failure), clients can reconnect to the same session without losing any data.
Sessions also have metadata associated with them, which can be used for operations that target specific sessions or groups of sessions.

Java and Android
final Session session = Diffusion
    .sessions()
    .principal("<principal>")
    .password("<password>")
    .open("<url>");
JavaScript
const options : diffusion.Options = {
    host : '<url>',
    principal : '<principal>',
    credentials : '<password'>
};

const session = await diffusion.connect(options);

console.log(`Connected to Diffusion via session ${session.sessionId}`);
.NET
string url = "<url>";
string principal = "<principal>";
string password = "<password>";

var factory = Diffusion.Sessions
    .Principal(principal)
    .Credentials(Diffusion.Credentials.Password(password));

ISession session = factory.Open(url);
WriteLine($"Connected to Diffusion via session {session}!");
C
CREDENTIALS_T *credentials = credentials_create_password("<password>");

SESSION_T *session = session_create("<url>", "<principal>", credentials, NULL, NULL, NULL);
Python
async with diffusion.Session(
    url="<url>",
    principal="<principal>",
    credentials=diffusion.Credentials("<password>")
) as session:
    print(f"Connected to Diffusion via session {session.session_id}!")
Apple
let url = URL.init(string: "<url>")!

let configuration = PTDiffusionMutableSessionConfiguration()
configuration.principal = "<principal>"
configuration.credentials = PTDiffusionCredentials.init(password: "<password>")

PTDiffusionSession.open(with: url, configuration: configuration) { (session, error) in
    print("Connected to Diffusion via session %@", session!)
}