C# Класс GSF.Communication.TcpClient

Represents a TCP-based communication client.
The TcpClient.Client socket can be bound to a specified interface on a machine with multiple interfaces by specifying the interface in the ClientBase.ConnectionString (Example: "Server=localhost:8888; Interface=127.0.0.1")
Наследование: ClientBase
Показать файл Открыть проект Примеры использования класса

Private Properties

Свойство Тип Описание
ConnectAsync void
DumpPayloads void
ProcessConnect void
ProcessIntegratedSecurityAuthentication void
ProcessReceivePayloadAware void
ProcessReceivePayloadUnaware void
ProcessSend void
ReceivePayloadAwareAsync void
ReceivePayloadUnawareAsync void
SendPayloadAsync void
TerminateConnection void

Открытые методы

Метод Описание
ConnectAsync ( ) : WaitHandle

Connects the TcpClient to the server asynchronously.

Disconnect ( ) : void

Disconnects the TcpClient from the connected server synchronously.

LoadSettings ( ) : void

Loads saved TcpClient settings from the config file if the ClientBase.PersistSettings property is set to true.

Read ( byte buffer, int startIndex, int length ) : int

Reads a number of bytes from the current received data buffer and writes those bytes into a byte array at the specified offset.

This function should only be called from within the ClientBase.ReceiveData event handler. Calling this method outside this event will have unexpected results.

SaveSettings ( ) : void

Saves TcpClient settings to the config file if the ClientBase.PersistSettings property is set to true.

TcpClient ( ) : System

Initializes a new instance of the TcpClient class.

TcpClient ( IContainer container ) : System

Initializes a new instance of the TcpClient class.

TcpClient ( string connectString ) : System

Initializes a new instance of the TcpClient class.

Защищенные методы

Метод Описание
Dispose ( bool disposing ) : void

Releases the unmanaged resources used by the TcpClient and optionally releases the managed resources.

OnReceiveDataException ( Exception ex ) : void

Raises the ClientBase.ReceiveDataException event.

OnReceiveDataException ( SocketException ex ) : void

Raises the ClientBase.ReceiveDataException event.

OnSendDataException ( Exception ex ) : void

Raises the ClientBase.SendDataException event.

SendDataAsync ( byte data, int offset, int length ) : WaitHandle

Sends data to the server asynchronously.

ValidateConnectionString ( string connectionString ) : void

Validates the specified connectionString.

Приватные методы

Метод Описание
ConnectAsync ( ConnectState connectState ) : void

Initiates an asynchronous connection attempt.

DumpPayloads ( ) : void

Dumps payloads from the send queue when the send queue grows too large.

ProcessConnect ( ConnectState connectState ) : void

Callback method for asynchronous connect operation.

ProcessIntegratedSecurityAuthentication ( IAsyncResult asyncResult ) : void
ProcessReceivePayloadAware ( ReceiveState receiveState ) : void

Callback method for asynchronous receive operation of payload data in "payload-aware" mode.

ProcessReceivePayloadUnaware ( ReceiveState receiveState ) : void

Callback method for asynchronous receive operation of payload data in "payload-unaware" mode.

ProcessSend ( SendState sendState ) : void

Callback method for asynchronous send operation.

ReceivePayloadAwareAsync ( ReceiveState receiveState ) : void

Initiate method for asynchronous receive operation of payload data in "payload-aware" mode.

ReceivePayloadUnawareAsync ( ReceiveState receiveState ) : void

Initiate method for asynchronous receive operation of payload data in "payload-unaware" mode.

SendPayloadAsync ( SendState sendState ) : void

Sends a payload on the socket.

TerminateConnection ( CancellationToken cancellationToken ) : void

Processes the termination of client.

Описание методов

ConnectAsync() публичный Метод

Connects the TcpClient to the server asynchronously.
Attempt is made to connect the when it is not disconnected.
public ConnectAsync ( ) : WaitHandle
Результат System.Threading.WaitHandle

Disconnect() публичный Метод

Disconnects the TcpClient from the connected server synchronously.
public Disconnect ( ) : void
Результат void

Dispose() защищенный Метод

Releases the unmanaged resources used by the TcpClient and optionally releases the managed resources.
protected Dispose ( bool disposing ) : void
disposing bool true to release both managed and unmanaged resources; false to release only unmanaged resources.
Результат void

LoadSettings() публичный Метод

Loads saved TcpClient settings from the config file if the ClientBase.PersistSettings property is set to true.
public LoadSettings ( ) : void
Результат void

OnReceiveDataException() защищенный Метод

Raises the ClientBase.ReceiveDataException event.
protected OnReceiveDataException ( Exception ex ) : void
ex System.Exception Exception to send to event.
Результат void

OnReceiveDataException() защищенный Метод

Raises the ClientBase.ReceiveDataException event.
protected OnReceiveDataException ( SocketException ex ) : void
ex System.Net.Sockets.SocketException Exception to send to event.
Результат void

OnSendDataException() защищенный Метод

Raises the ClientBase.SendDataException event.
protected OnSendDataException ( Exception ex ) : void
ex System.Exception Exception to send to event.
Результат void

Read() публичный Метод

Reads a number of bytes from the current received data buffer and writes those bytes into a byte array at the specified offset.
This function should only be called from within the ClientBase.ReceiveData event handler. Calling this method outside this event will have unexpected results.
No received data buffer has been defined to read. is null. /// or is less than 0 -or- /// and will exceed length. ///
public Read ( byte buffer, int startIndex, int length ) : int
buffer byte Destination buffer used to hold copied bytes.
startIndex int 0-based starting index into destination to begin writing data.
length int The number of bytes to read from current received data buffer and write into .
Результат int

SaveSettings() публичный Метод

Saves TcpClient settings to the config file if the ClientBase.PersistSettings property is set to true.
public SaveSettings ( ) : void
Результат void

SendDataAsync() защищенный Метод

Sends data to the server asynchronously.
protected SendDataAsync ( byte data, int offset, int length ) : WaitHandle
data byte The buffer that contains the binary data to be sent.
offset int The zero-based position in the at which to begin sending data.
length int The number of bytes to be sent from starting at the .
Результат WaitHandle

TcpClient() публичный Метод

Initializes a new instance of the TcpClient class.
public TcpClient ( ) : System
Результат System

TcpClient() публичный Метод

Initializes a new instance of the TcpClient class.
public TcpClient ( IContainer container ) : System
container IContainer object that contains the .
Результат System

TcpClient() публичный Метод

Initializes a new instance of the TcpClient class.
public TcpClient ( string connectString ) : System
connectString string Connect string of the . See for format.
Результат System

ValidateConnectionString() защищенный Метод

Validates the specified connectionString.
Server property is missing. Server property is invalid. Server port value is not between and .
protected ValidateConnectionString ( string connectionString ) : void
connectionString string Connection string to be validated.
Результат void