Table of Contents

Method ConnectAsync

Namespace
OBSStudioClient
Assembly
OBSClient.dll

ConnectAsync(bool, string, string, int, EventSubscriptions, CancellationToken)

Opens the connection to OBS Studio and tries to authenticate the session.

public Task<bool> ConnectAsync(bool autoReconnect = false, string password = "", string hostname = "localhost", int port = 4455, EventSubscriptions eventSubscription = EventSubscriptions.All, CancellationToken cancellationToken = default)

Parameters

autoReconnect bool

Value to indicate whether the client should automatically try to reconnect to OBS Studio.

password string

The OBS Studio WebSockets password or empty to connect without authentication. Defaults to empty.

hostname string

The hostname of the computer running OBS Studio to connect to. Defaults to "localhost".

port int

The Port on which the OBS Studio WebSocket interface is listenting. Default to 4455.

eventSubscription EventSubscriptions

The events to subscribe to. Defaults to All events.

cancellationToken CancellationToken

A token that ends the attempt to connect, as Disconnect() would: the connection that is being opened is closed and AutoReconnect is switched off, so the client does not go on trying what the caller no longer wants.

Returns

Task<bool>

true when OBS Studio accepted the session: the connection is open, the authentication succeeded and ConnectionState is Connected. false otherwise.

Remarks

The task completes when the handshake with OBS Studio is done, so a request can be sent as soon as true is returned. It returns false, and does not throw, when OBS Studio cannot be reached (within 2 seconds), when the handshake is not completed within 10 seconds, when the password is refused, or when Disconnect() is called in the meantime. With autoReconnect the client keeps trying (see AutoReconnect). When the client is not Disconnected, nothing is done and true is returned: call Disconnect() first to connect with other settings.

Exceptions

ArgumentOutOfRangeException

port is not between 1 and 65535.

ArgumentException

hostname is not a valid host name.

OperationCanceledException

cancellationToken was cancelled before the call completed: the attempt was ended, and AutoReconnect switched off. A token that is cancelled after the call completed has no effect.