# Sandbox.WebSocket.Connect

## Overload 1

```csharp
System.Threading.Tasks.Task Connect(string websocketUri, System.Threading.CancellationToken ct = null)
```

Establishes a connection to an external WebSocket service.

### Parameters

- `websocketUri` (`string`): The WebSocket URI to connect to. For example, "ws://hostname.local:1280/" for unencrypted WebSocket or "wss://hostname.local:1281/" for encrypted.
- `ct` (`System.Threading.CancellationToken`), default `null`: A `T:System.Threading.CancellationToken` which allows the connection attempt to be aborted if necessary.

### Returns

`System.Threading.Tasks.Task`: A `T:System.Threading.Tasks.Task` which completes when the connection is established, or throws if it failed to connect.

## Overload 2

```csharp
System.Threading.Tasks.Task Connect(string websocketUri, Dictionary<string,string> headers, System.Threading.CancellationToken ct = null)
```

### Parameters

- `websocketUri` (`string`)
- `headers` (`Dictionary<string,string>`)
- `ct` (`System.Threading.CancellationToken`), default `null`

### Returns

`System.Threading.Tasks.Task`

Declared in [Sandbox.WebSocket](/api/Sandbox.WebSocket).
Assembly: `Sandbox.Engine`.
