Skip to content

Class TcpConnection

A raw TCP byte stream, for a service that speaks plain lines, such as a MUD or a server of your own, and the base class for the telnet connection. Connect returns at once: the name lookup, the connect, the reads, and the writes all run on background threads. A connect that fails arrives through Closed, and bytes sent before the connect completes go out once it does.

Declaration
public class TcpConnection : ITerminalConnection

Derived:
DarkEffekt.Terminal.TelnetConnection

Implements:
DarkEffekt.Terminal.ITerminalConnection

Whether this platform has sockets. False in a WebGL player, where DarkEffekt.Terminal.WebSocketConnection reaches a host and this cannot.

Declaration
public static bool IsSupported { get; }
Declaration
public string Host { get; }
Declaration
public int Port { get; }
Declaration
public bool IsConnected { get; }

Starts connecting and returns at once; Connected or Closed reports the outcome.

Declaration
public void Connect()

The stream is open. Runs on the background thread, before the first read and before Connected.

Declaration
protected virtual void OnConnected()

Processes n bytes read from the wire. The base class raises DataReceived directly.

Declaration
protected virtual void HandleIncoming(byte[] buffer, int n)
Type Name
System.Byte[] buffer
System.Int32 n
Declaration
protected void RaiseDataReceived(byte[] data)
Type Name
System.Byte[] data

Queues bytes for the far end. Never blocks on the network.

Declaration
public virtual void Send(byte[] data, int offset, int count)
Type Name
System.Byte[] data
System.Int32 offset
System.Int32 count

Queues bytes for the wire as they are. The array must not change afterward.

Declaration
protected void SendRaw(byte[] data)
Type Name
System.Byte[] data

The terminal grid changed size. Connections that can pass this on do.

Declaration
public virtual void NotifyResize(int cols, int rows)
Type Name
System.Int32 cols
System.Int32 rows

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
public void Dispose()

The stream is open and data can flow.

Declaration
public event Action Connected

System.Action

Declaration
public event Action<byte[]> DataReceived

System.Action<System.Byte[]>

Declaration
public event Action<CloseReason> Closed

System.Action<DarkEffekt.Terminal.CloseReason>