> For the complete documentation index, see [llms.txt](https://kinematicsoup.gitbook.io/reactor/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinematicsoup.gitbook.io/reactor/api-reference/ks.reactor.client.unity/ks.reactor.client.unity.ksconnect.md).

# Class ksConnect

Namespace: [KS.Reactor.Client.Unity](/reactor/api-reference/ks.reactor.client.unity.md)\
Assembly: KSUnity-Source.dll

Reactor Connection component for connecting to Reactor server rooms and registering event handlers.

```csharp
public class ksConnect : MonoBehaviour
```

#### Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) ← Object ← Component ← Behaviour ← MonoBehaviour ← [ksConnect](/reactor/api-reference/ks.reactor.client.unity/ks.reactor.client.unity.ksconnect.md)

#### Inherited Members

MonoBehaviour.IsInvoking(), MonoBehaviour.CancelInvoke(), MonoBehaviour.Invoke(string, float), MonoBehaviour.InvokeRepeating(string, float, float), MonoBehaviour.CancelInvoke(string), MonoBehaviour.IsInvoking(string), MonoBehaviour.StartCoroutine(string), MonoBehaviour.StartCoroutine(string, object), MonoBehaviour.StartCoroutine(IEnumerator), MonoBehaviour.StartCoroutine\_Auto(IEnumerator), MonoBehaviour.StopCoroutine(IEnumerator), MonoBehaviour.StopCoroutine(Coroutine), MonoBehaviour.StopCoroutine(string), MonoBehaviour.StopAllCoroutines(), MonoBehaviour.print(object), MonoBehaviour.destroyCancellationToken, MonoBehaviour.useGUILayout, MonoBehaviour.runInEditMode, Behaviour.enabled, Behaviour.isActiveAndEnabled, Component.GetComponent(Type), Component.GetComponent\<T>(), Component.TryGetComponent(Type, out Component), Component.TryGetComponent\<T>(out T), Component.GetComponent(string), Component.GetComponentInChildren(Type, bool), Component.GetComponentInChildren(Type), Component.GetComponentInChildren\<T>(bool), Component.GetComponentInChildren\<T>(), Component.GetComponentsInChildren(Type, bool), Component.GetComponentsInChildren(Type), Component.GetComponentsInChildren\<T>(bool), Component.GetComponentsInChildren\<T>(bool, List\<T>), Component.GetComponentsInChildren\<T>(), Component.GetComponentsInChildren\<T>(List\<T>), Component.GetComponentInParent(Type, bool), Component.GetComponentInParent(Type), Component.GetComponentInParent\<T>(bool), Component.GetComponentInParent\<T>(), Component.GetComponentsInParent(Type, bool), Component.GetComponentsInParent(Type), Component.GetComponentsInParent\<T>(bool), Component.GetComponentsInParent\<T>(bool, List\<T>), Component.GetComponentsInParent\<T>(), Component.GetComponents(Type), Component.GetComponents(Type, List\<Component>), Component.GetComponents\<T>(List\<T>), Component.GetComponents\<T>(), Component.CompareTag(string), Component.SendMessageUpwards(string, object, SendMessageOptions), Component.SendMessageUpwards(string, object), Component.SendMessageUpwards(string), Component.SendMessageUpwards(string, SendMessageOptions), Component.SendMessage(string, object), Component.SendMessage(string), Component.SendMessage(string, object, SendMessageOptions), Component.SendMessage(string, SendMessageOptions), Component.BroadcastMessage(string, object, SendMessageOptions), Component.BroadcastMessage(string, object), Component.BroadcastMessage(string), Component.BroadcastMessage(string, SendMessageOptions), Component.transform, Component.gameObject, Component.tag, Object.GetInstanceID(), Object.GetHashCode(), Object.Equals(object), Object.Instantiate(Object, Vector3, Quaternion), Object.Instantiate(Object, Vector3, Quaternion, Transform), Object.Instantiate(Object), Object.Instantiate(Object, Transform), Object.Instantiate(Object, Transform, bool), Object.Instantiate\<T>(T), Object.Instantiate\<T>(T, Vector3, Quaternion), Object.Instantiate\<T>(T, Vector3, Quaternion, Transform), Object.Instantiate\<T>(T, Transform), Object.Instantiate\<T>(T, Transform, bool), Object.Destroy(Object, float), Object.Destroy(Object), Object.DestroyImmediate(Object, bool), Object.DestroyImmediate(Object), Object.FindObjectsOfType(Type), Object.FindObjectsOfType(Type, bool), Object.FindObjectsByType(Type, FindObjectsSortMode), Object.FindObjectsByType(Type, FindObjectsInactive, FindObjectsSortMode), Object.DontDestroyOnLoad(Object), Object.DestroyObject(Object, float), Object.DestroyObject(Object), Object.FindSceneObjectsOfType(Type), Object.FindObjectsOfTypeIncludingAssets(Type), Object.FindObjectsOfType\<T>(), Object.FindObjectsByType\<T>(FindObjectsSortMode), Object.FindObjectsOfType\<T>(bool), Object.FindObjectsByType\<T>(FindObjectsInactive, FindObjectsSortMode), Object.FindObjectOfType\<T>(), Object.FindObjectOfType\<T>(bool), Object.FindFirstObjectByType\<T>(), Object.FindAnyObjectByType\<T>(), Object.FindFirstObjectByType\<T>(FindObjectsInactive), Object.FindAnyObjectByType\<T>(FindObjectsInactive), Object.FindObjectsOfTypeAll(Type), Object.FindObjectOfType(Type), Object.FindFirstObjectByType(Type), Object.FindAnyObjectByType(Type), Object.FindObjectOfType(Type, bool), Object.FindFirstObjectByType(Type, FindObjectsInactive), Object.FindAnyObjectByType(Type, FindObjectsInactive), Object.ToString(), Object.name, Object.hideFlags, [object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals\(system-object\)), [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals\(system-object-system-object\)), [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode), [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype), [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone), [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals), [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Fields

### ConnectMode <a href="#ks_reactor_client_unity_ksconnect_connectmode" id="ks_reactor_client_unity_ksconnect_connectmode"></a>

```csharp
[FormerlySerializedAs("ConnectionMethod")]
[Tooltip("Process used by the script to find a room.")]
public ksConnect.ConnectModes ConnectMode
```

#### Field Value

[ksConnect](/reactor/api-reference/ks.reactor.client.unity/ks.reactor.client.unity.ksconnect.md).[ConnectModes](/reactor/api-reference/ks.reactor.client.unity/ks.reactor.client.unity.ksconnect/ks.reactor.client.unity.ksconnect.connectmodes.md)

### ConnectOnStart <a href="#ks_reactor_client_unity_ksconnect_connectonstart" id="ks_reactor_client_unity_ksconnect_connectonstart"></a>

```csharp
[Tooltip("When enabled, the script will attempt to connect to a room when the script is started.")]
public bool ConnectOnStart
```

#### Field Value

[bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### ConnectProtocol <a href="#ks_reactor_client_unity_ksconnect_connectprotocol" id="ks_reactor_client_unity_ksconnect_connectprotocol"></a>

```csharp
[Tooltip("Connection protocol to use for connections.")]
public ksConnect.ConnectProtocols ConnectProtocol
```

#### Field Value

[ksConnect](/reactor/api-reference/ks.reactor.client.unity/ks.reactor.client.unity.ksconnect.md).[ConnectProtocols](/reactor/api-reference/ks.reactor.client.unity/ks.reactor.client.unity.ksconnect/ks.reactor.client.unity.ksconnect.connectprotocols.md)

### OnConnect <a href="#ks_reactor_client_unity_ksconnect_onconnect" id="ks_reactor_client_unity_ksconnect_onconnect"></a>

```csharp
[Tooltip("Event handlers called when connecting to a room.")]
public UnityEvent<ksConnect.ConnectEvent> OnConnect
```

#### Field Value

UnityEvent<[ksConnect](/reactor/api-reference/ks.reactor.client.unity/ks.reactor.client.unity.ksconnect.md).[ConnectEvent](/reactor/api-reference/ks.reactor.client.unity/ks.reactor.client.unity.ksconnect/ks.reactor.client.unity.ksconnect.connectevent.md)>

### OnDisconnect <a href="#ks_reactor_client_unity_ksconnect_ondisconnect" id="ks_reactor_client_unity_ksconnect_ondisconnect"></a>

```csharp
[Tooltip("Event handlers called when disconnected from a room.")]
public UnityEvent<ksConnect.DisconnectEvent> OnDisconnect
```

#### Field Value

UnityEvent<[ksConnect](/reactor/api-reference/ks.reactor.client.unity/ks.reactor.client.unity.ksconnect.md).[DisconnectEvent](/reactor/api-reference/ks.reactor.client.unity/ks.reactor.client.unity.ksconnect/ks.reactor.client.unity.ksconnect.disconnectevent.md)>

### OnGetRooms <a href="#ks_reactor_client_unity_ksconnect_ongetrooms" id="ks_reactor_client_unity_ksconnect_ongetrooms"></a>

```csharp
[Tooltip("Event handlers called when after getting the list of running rooms. For REMOTE and LOCAL connections this is called with a single room. If there are no handlers, it will automatically connect to the first room. If there are any handlers, it will not connect automatically and the handlers are responsible for making a connection.")]
public UnityEvent<ksConnect.GetRoomsEvent> OnGetRooms
```

#### Field Value

UnityEvent<[ksConnect](/reactor/api-reference/ks.reactor.client.unity/ks.reactor.client.unity.ksconnect.md).[GetRoomsEvent](/reactor/api-reference/ks.reactor.client.unity/ks.reactor.client.unity.ksconnect/ks.reactor.client.unity.ksconnect.getroomsevent.md)>

### RemoteHost <a href="#ks_reactor_client_unity_ksconnect_remotehost" id="ks_reactor_client_unity_ksconnect_remotehost"></a>

```csharp
[FormerlySerializedAs("Host")]
[Tooltip("Remote host address used for connections using the REMOTE connect mode.")]
public string RemoteHost
```

#### Field Value

[string](https://learn.microsoft.com/dotnet/api/system.string)

### RemotePort <a href="#ks_reactor_client_unity_ksconnect_remoteport" id="ks_reactor_client_unity_ksconnect_remoteport"></a>

```csharp
[FormerlySerializedAs("Port")]
[Tooltip("Remote port used for connections using the REMOTE connect mode.")]
public ushort RemotePort
```

#### Field Value

[ushort](https://learn.microsoft.com/dotnet/api/system.uint16)

### Room <a href="#ks_reactor_client_unity_ksconnect_room" id="ks_reactor_client_unity_ksconnect_room"></a>

```csharp
[Obsolete("Get the room from the event handlers instead.")]
public ksRoom Room
```

#### Field Value

[ksRoom](/reactor/api-reference/ks.reactor.client.unity/ks.reactor.client.unity.ksroom.md)

### SecureLocalWebSockets <a href="#ks_reactor_client_unity_ksconnect_securelocalwebsockets" id="ks_reactor_client_unity_ksconnect_securelocalwebsockets"></a>

```csharp
[Tooltip("Use a secure web socket connection protocol for connecting to localhost in webgl builds using the LOCAL connect mode.")]
public bool SecureLocalWebSockets
```

#### Field Value

[bool](https://learn.microsoft.com/dotnet/api/system.boolean)

## Methods

### BeginConnect() <a href="#ks_reactor_client_unity_ksconnect_beginconnect" id="ks_reactor_client_unity_ksconnect_beginconnect"></a>

Begin connecting to a room.

```csharp
public void BeginConnect()
```

### Connect(ksRoomInfo, params ksMultiType\[]) <a href="#ks_reactor_client_unity_ksconnect_connect_ks_reactor_ksroominfo_ks_reactor_ksmultitype" id="ks_reactor_client_unity_ksconnect_connect_ks_reactor_ksroominfo_ks_reactor_ksmultitype"></a>

Connect to a room.

```csharp
public ksRoom Connect(ksRoomInfo roomInfo, params ksMultiType[] connectParams)
```

#### Parameters

`roomInfo` [ksRoomInfo](/reactor/api-reference/ks.reactor/ks.reactor.ksroominfo.md)

Room connection info

`connectParams` [ksMultiType](/reactor/api-reference/ks.reactor/ks.reactor.ksmultitype.md)\[]

Room connection parameters passed to the server OnAuthenticate handler.

#### Returns

[ksRoom](/reactor/api-reference/ks.reactor.client.unity/ks.reactor.client.unity.ksroom.md)

The room connection.

### Disconnect(bool) <a href="#ks_reactor_client_unity_ksconnect_disconnect_system_boolean" id="ks_reactor_client_unity_ksconnect_disconnect_system_boolean"></a>

```csharp
[Obsolete("Call Room.Disconnect instead.")]
public void Disconnect(bool immediate)
```

#### Parameters

`immediate` [bool](https://learn.microsoft.com/dotnet/api/system.boolean)
