> 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/ks.reactor.client.ksconnection.md).

# Class ksConnection

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

Base class for network connections.

```csharp
public abstract class ksConnection
```

#### Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) ← [ksConnection](/reactor/api-reference/ks.reactor.client/ks.reactor.client.ksconnection.md)

#### Derived

[ksDirectConnection](/reactor/api-reference/ks.reactor.client.unity/ks.reactor.client.unity.ksdirectconnection.md), [ksRUDPConnection](/reactor/api-reference/ks.reactor.client/ks.reactor.client.ksrudpconnection.md), [ksTCPConnection](/reactor/api-reference/ks.reactor.client/ks.reactor.client.kstcpconnection.md), [ksWSConnection](/reactor/api-reference/ks.reactor.client.unity/ks.reactor.client.unity.kswsconnection.md)

#### Inherited Members

[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

### m\_host <a href="#ks_reactor_client_ksconnection_m_host" id="ks_reactor_client_ksconnection_m_host"></a>

```csharp
protected string m_host
```

#### Field Value

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

### m\_port <a href="#ks_reactor_client_ksconnection_m_port" id="ks_reactor_client_ksconnection_m_port"></a>

```csharp
protected ushort m_port
```

#### Field Value

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

## Properties

### Address <a href="#ks_reactor_client_ksconnection_address" id="ks_reactor_client_ksconnection_address"></a>

Return the host and port as a single address string.

```csharp
public string Address { get; }
```

#### Property Value

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

### IsConnected <a href="#ks_reactor_client_ksconnection_isconnected" id="ks_reactor_client_ksconnection_isconnected"></a>

Check if a connection to the server is open.

```csharp
public abstract bool IsConnected { get; }
```

#### Property Value

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

### ReadProgress <a href="#ks_reactor_client_ksconnection_readprogress" id="ks_reactor_client_ksconnection_readprogress"></a>

Get the progress of the current read operation.

```csharp
public abstract ksFrameInfo ReadProgress { get; }
```

#### Property Value

[ksFrameInfo](/reactor/api-reference/ks.reactor.client/ks.reactor.client.ksframeinfo.md)

### WriteProgress <a href="#ks_reactor_client_ksconnection_writeprogress" id="ks_reactor_client_ksconnection_writeprogress"></a>

Get the progress of the current write operation.

```csharp
public abstract ksFrameInfo WriteProgress { get; }
```

#### Property Value

[ksFrameInfo](/reactor/api-reference/ks.reactor.client/ks.reactor.client.ksframeinfo.md)

## Methods

### Connect(string, ushort, ConnectHandler, object) <a href="#ks_reactor_client_ksconnection_connect_system_string_system_uint16_ks_reactor_client_ksconnection_co" id="ks_reactor_client_ksconnection_connect_system_string_system_uint16_ks_reactor_client_ksconnection_co"></a>

Establish a connection to a server.

```csharp
public abstract void Connect(string host, ushort port, ksConnection.ConnectHandler callback, object asyncState = null)
```

#### Parameters

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

server host name

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

server port

`callback` [ksConnection](/reactor/api-reference/ks.reactor.client/ks.reactor.client.ksconnection.md).[ConnectHandler](/reactor/api-reference/ks.reactor.client/ks.reactor.client.ksconnection/ks.reactor.client.ksconnection.connecthandler.md)

callback to invoke when the connection attempt completes

`asyncState` [object](https://learn.microsoft.com/dotnet/api/system.object)

asynchronous state

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

Disconnect from the server.

```csharp
public abstract void Disconnect(bool immediate)
```

#### Parameters

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

If this is false, then queued write operations will complete before disconnecting.

### Read(Segment, IOHandler, object) <a href="#ks_reactor_client_ksconnection_read_ks_reactor_ksstreambuffer_segment_ks_reactor_client_ksconnection" id="ks_reactor_client_ksconnection_read_ks_reactor_ksstreambuffer_segment_ks_reactor_client_ksconnection"></a>

Read data from the connection into a stream buffer segment.

```csharp
public abstract void Read(ksStreamBuffer.Segment segment, ksConnection.IOHandler callback, object asyncState = null)
```

#### Parameters

`segment` [ksStreamBuffer](/reactor/api-reference/ks.reactor/ks.reactor.ksstreambuffer.md).[Segment](/reactor/api-reference/ks.reactor/ks.reactor.ksstreambuffer/ks.reactor.ksstreambuffer.segment.md)

segment of a larger stream buffer

`callback` [ksConnection](/reactor/api-reference/ks.reactor.client/ks.reactor.client.ksconnection.md).[IOHandler](/reactor/api-reference/ks.reactor.client/ks.reactor.client.ksconnection/ks.reactor.client.ksconnection.iohandler.md)

callback to invoke when the read operation completes

`asyncState` [object](https://learn.microsoft.com/dotnet/api/system.object)

asynchronous state

### TryResolveHost(string, out IPAddress) <a href="#ks_reactor_client_ksconnection_tryresolvehost_system_string_system_net_ipaddress" id="ks_reactor_client_ksconnection_tryresolvehost_system_string_system_net_ipaddress"></a>

Try to resolve a host string to an IP Address. This method first checks if the string is a valid IP address and if that fails it will attempt to resolve the address using DNS services.

```csharp
protected bool TryResolveHost(string host, out IPAddress ipAddress)
```

#### Parameters

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

Host or IP string

`ipAddress` [IPAddress](https://learn.microsoft.com/dotnet/api/system.net.ipaddress)

IP Address

#### Returns

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

True if a valid IP address was resolved.

### Write(Segment, IOHandler, object) <a href="#ks_reactor_client_ksconnection_write_ks_reactor_ksstreambuffer_segment_ks_reactor_client_ksconnectio" id="ks_reactor_client_ksconnection_write_ks_reactor_ksstreambuffer_segment_ks_reactor_client_ksconnectio"></a>

Read data from the connection into a stream buffer segment.

```csharp
public abstract void Write(ksStreamBuffer.Segment segment, ksConnection.IOHandler callback, object asyncState = null)
```

#### Parameters

`segment` [ksStreamBuffer](/reactor/api-reference/ks.reactor/ks.reactor.ksstreambuffer.md).[Segment](/reactor/api-reference/ks.reactor/ks.reactor.ksstreambuffer/ks.reactor.ksstreambuffer.segment.md)

segment of a larger stream buffer

`callback` [ksConnection](/reactor/api-reference/ks.reactor.client/ks.reactor.client.ksconnection.md).[IOHandler](/reactor/api-reference/ks.reactor.client/ks.reactor.client.ksconnection/ks.reactor.client.ksconnection.iohandler.md)

callback to invoke when the write operation completes

`asyncState` [object](https://learn.microsoft.com/dotnet/api/system.object)

asynchronous state

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

Called when the connection is disconnected.

```csharp
public abstract event ksConnection.DisconnectHandler OnDisconnect
```

#### Event Type

[ksConnection](/reactor/api-reference/ks.reactor.client/ks.reactor.client.ksconnection.md).[DisconnectHandler](/reactor/api-reference/ks.reactor.client/ks.reactor.client.ksconnection/ks.reactor.client.ksconnection.disconnecthandler.md)
