Table of Contents

Class TCPBase

Namespace
NominalSystems.External
Assembly
NominalSystems.External.dll
public class TCPBase
Inheritance
TCPBase
Derived

Constructors

TCPBase()

public TCPBase()

Fields

Client

The client connection to a server

protected TcpClient Client

Field Value

TcpClient

Reader

Used to read binary data from the network stream

protected BinaryReader Reader

Field Value

BinaryReader

Stream

The network stream used to send and receive data over the network

protected NetworkStream Stream

Field Value

NetworkStream

Writer

Used to write binary data to the network stream

protected BinaryWriter Writer

Field Value

BinaryWriter

Properties

ClientConnected

Boolean to store the connected status of the TcpClient, true is Connected

public bool ClientConnected { get; }

Property Value

bool

Methods

ClearBuffer()

Clears the buffer of any data

public void ClearBuffer()

DataAvailable()

Checks if there is data in the buffer to be received

public bool DataAvailable()

Returns

bool

True if there is data to be received

PublishByte(byte, bool)

Sends a byte over the connection

public void PublishByte(byte bytePayload, bool useLengthHeader = false)

Parameters

bytePayload byte

The byte to send

useLengthHeader bool

Enables sending the size of the byte before the value of the byte

PublishByteArray(byte[], bool)

Sends a byte array over the connection

public void PublishByteArray(byte[] byteArrayPayload, bool useArrayLengthHeader = true)

Parameters

byteArrayPayload byte[]

The byte array to send

useArrayLengthHeader bool

Enables sending the length of the byte array before the array. Required for the matching Receive functions

PublishDouble(double, bool)

Sends a double over the connection

public void PublishDouble(double doublePayload, bool useLengthHeader = false)

Parameters

doublePayload double

The double to send

useLengthHeader bool

Enables sending the size of the double before the value of the double

PublishDoubleArray(double[], bool)

Sends an array of doubles over the connection

public void PublishDoubleArray(double[] doubleArrayPayload, bool useArrayLengthHeader = true)

Parameters

doubleArrayPayload double[]

The double array to send

useArrayLengthHeader bool

Enables sending the size of the double array before the values of the double array

PublishFloat(float, bool)

Sends a float over the connection

public void PublishFloat(float floatPayload, bool useLengthHeader = false)

Parameters

floatPayload float

The float to send

useLengthHeader bool

Enables sending the size of the float before the value of the float

PublishFloatArray(float[], bool)

Sends an array of floats over the connection

public void PublishFloatArray(float[] floatArrayPayload, bool useArrayLengthHeader = true)

Parameters

floatArrayPayload float[]

The float array to send

useArrayLengthHeader bool

Enables sending the size of the float array before the values of the float array

PublishInt(int, bool)

Sends an integer over the connection

public void PublishInt(int intPayload, bool useLengthHeader = false)

Parameters

intPayload int

The integer to send

useLengthHeader bool

Enables sending the size of the integer before the value of the integer

PublishIntArray(int[], bool)

Sends an array of integers over the connection

public void PublishIntArray(int[] intArrayPayload, bool useArrayLengthHeader = true)

Parameters

intArrayPayload int[]

The integer array to send

useArrayLengthHeader bool

Enables sending the size of the integer array before the values of the integer array

PublishLine(string, bool)

Sends a string array over the connection, with a NewLine terminator '\n' included after the String. Preceded by an integer of the individual string lengths (including the NewLine terminator) if enabled

public void PublishLine(string stringPayload, bool useLengthHeader = false)

Parameters

stringPayload string

The message to send over the connection as a string without the NewLine terminator

useLengthHeader bool

Enables sending the length of the String with the NewLine terminator included before the String as Bytes

PublishLineArray(string[], bool, bool)

Called to write an array of Strings with a NewLine terminator included after each String

public void PublishLineArray(string[] stringArrayPayload, bool useLengthHeader = false, bool useArrayLengthHeader = true)

Parameters

stringArrayPayload string[]

The String array to send over the connection

useLengthHeader bool

Enables sending the length of the String with the NewLine terminator included before each String as Bytes

useArrayLengthHeader bool

Enables sending the length of the String array before the array. Required for the matching Receive functions

PublishString(string, bool)

Sends a string over the connection, preceded by an integer of it's length if enabled

public void PublishString(string stringPayload, bool useLengthHeader = true)

Parameters

stringPayload string

The message to send over the connection as a string

useLengthHeader bool

Enables sending the length of the string before the string. Required for the matching Receive functions

PublishStringArray(string[], bool, bool)

Sends a string array over the connection, preceded by an integer of the individual string lengths if enabled

public void PublishStringArray(string[] stringArrayPayload, bool useLengthHeader = true, bool useArrayLengthHeader = true)

Parameters

stringArrayPayload string[]

The message to send over the connection as a string

useLengthHeader bool

Enables sending the length of the string before the string. Required for the matching Receive functions

useArrayLengthHeader bool

Enables sending the length of the Array before the String Array. Required for the matching Receive functions

ReceiveByte()

Receives a byte over the connection, with a default timeout of infinite

public byte? ReceiveByte()

Returns

byte?

The received byte

ReceiveByte(int)

Receives a byte over the connection with a specified timeout

public byte? ReceiveByte(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

byte?

The received byte

ReceiveByteArray()

Receives a byte array over the connection,preceded by an integer of the array length, with a default timeout of infinite. Will return null if the read failed

public byte[]? ReceiveByteArray()

Returns

byte[]

The received byte array

ReceiveByteArray(int)

Receives a byte array over the connection,preceded by an integer of the array length, with a specified timeout. Will return null if the read failed

public byte[]? ReceiveByteArray(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

byte[]

The received byte array

ReceiveDouble()

Receives a double over the connection, with a default timeout of infinite

public double? ReceiveDouble()

Returns

double?

The received double

ReceiveDouble(int)

Receives a double over the connection with a specified timeout

public double? ReceiveDouble(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

double?

The received double

ReceiveDoubleArray()

Receives a double array over the connection, with a default timeout of infinite

public double[]? ReceiveDoubleArray()

Returns

double[]

The received double array

ReceiveDoubleArray(int)

Receives a double array over the connection, with a specified timeout

public double[]? ReceiveDoubleArray(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

double[]

The received double array

ReceiveFloat()

Receives a float over the connection, with a default timeout of infinite

public float? ReceiveFloat()

Returns

float?

The received float

ReceiveFloat(int)

Receives an float over the connection with a specified timeout

public float? ReceiveFloat(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

float?

The received float

ReceiveFloatArray()

Receives a float array over the connection, with a default timeout of infinite

public float[]? ReceiveFloatArray()

Returns

float[]

The received float array

ReceiveFloatArray(int)

Receives a float array over the connection, with a specified timeout

public float[]? ReceiveFloatArray(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

float[]

The received float array

ReceiveInt()

Receives an integer over the connection, with a default timeout of infinite

public int? ReceiveInt()

Returns

int?

The received integer

ReceiveInt(int)

Receives an integer over the connection with a specified timeout

public int? ReceiveInt(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

int?

The received integer

ReceiveIntArray()

Receives a int array over the connection, with a default timeout of infinite.

public int[]? ReceiveIntArray()

Returns

int[]

The received int array

ReceiveIntArray(int)

Receives a int array over the connection, with a specified timeout

public int[]? ReceiveIntArray(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

int[]

The received int array

ReceiveLine()

Receives a string until the NewLine Value '\n' over the connection, with a default timeout of infinite

public string ReceiveLine()

Returns

string

The read data as a String

ReceiveLine(int)

Receives a string until the NewLine Value '\n' over the connection, with a specified timeout

public string ReceiveLine(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

string

The read data as a String

ReceiveLineArray()

Called to read an array of Strings with a NewLine terminator from over the connection, with a default timeout of infinite

public string[] ReceiveLineArray()

Returns

string[]

The read data as a String array

ReceiveLineArray(int)

Called to read an array of Strings with a NewLine terminator from over the connection, with a specified timeout

public string[] ReceiveLineArray(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

string[]

The read data as a String array

ReceiveString()

Receives a string over the connection, preceded by an integer of it's length, with a default timeout of infinite

public string ReceiveString()

Returns

string

The received string

ReceiveString(int)

Receives a string over the connection, preceded by an integer of it's length, with a specified timeout

public string ReceiveString(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

string

The received string

ReceiveStringArray()

Receives a string array over the connection, preceded by an integer of it's length, with a default timeout of infinite. Each string also needs to be preceded by an integer of it's character length.

public string[] ReceiveStringArray()

Returns

string[]

The received string array

ReceiveStringArray(int)

Receives a string array over the connection, preceded by an integer of it's length, with a specified timeout. Each string also needs to be preceded by an integer of it's character length.

public string[] ReceiveStringArray(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

string[]

The received string array

ReceiveStringUntil(string)

Called to read a string from over the connection until a designated terminator

public string ReceiveStringUntil(string terminator)

Parameters

terminator string

The terminator to read the buffer to

Returns

string

The read data as a String with the terminator

ReceiveStringUntil(string, int)

Called to read a string from over the connection until a designated terminator with a specified timeout

public string ReceiveStringUntil(string terminator, int timeout)

Parameters

terminator string

The terminator to read the buffer to

timeout int

[ms] The specified timeout

Returns

string

The read data as a String with the terminator