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

Represents a UDP-based communication server.

Use UdpServer when the primary purpose is to transmit data.

The UdpServer.Server socket can be bound to a specified interface on a machine with multiple interfaces by specifying the interface in the ServerBase.ConfigurationString (Example: "Port=8888; Clients=localhost:8989; Interface=127.0.0.1")

The UdpServer.Server socket can be used just for transmitting data without being bound to a local interface by specifying -1 for the port number in the ServerBase.ConfigurationString (Example: "Port=-1; Clients=localhost:8989")

Наследование: ServerBase
Показать файл Открыть проект Примеры использования класса

Private Properties

Свойство Тип Описание
AddUdpClient TransportProvider
AddUdpClient void
IdentifyClient TransportProvider
ProcessReceive void
ProcessSend void
ReceivePayloadAsync void
SendPayload void

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

Метод Описание
DisconnectOne ( System.Guid clientID ) : void

Disconnects the specified connected client.

LoadSettings ( ) : void

Loads saved TcpServer settings from the config file if the ServerBase.PersistSettings property is set to true.

Read ( System.Guid clientID, 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 ServerBase.ReceiveClientData event handler. Calling this method outside this event will have unexpected results.

SaveSettings ( ) : void

Saves TcpServer settings to the config file if the ServerBase.PersistSettings property is set to true.

Start ( ) : void

Starts the UdpServer synchronously and begins accepting client connections asynchronously.

Stop ( ) : void

Stops the UdpServer synchronously and disconnects all connected clients.

TryGetClient ( System.Guid clientID, TransportProvider &udpClient ) : bool

Gets the TransportProvider{EndPoint} object associated with the specified client ID.

UdpServer ( ) : System

Initializes a new instance of the UdpServer class.

UdpServer ( IContainer container ) : System

Initializes a new instance of the UdpServer class.

UdpServer ( string configString ) : System

Initializes a new instance of the UdpServer class.

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

Метод Описание
OnReceiveClientDataException ( System.Guid clientID, Exception ex ) : void

Raises the ServerBase.ReceiveClientDataException event.

OnSendClientDataException ( System.Guid clientID, Exception ex ) : void

Raises the ServerBase.SendClientDataException event.

SendDataToAsync ( System.Guid clientID, byte data, int offset, int length ) : WaitHandle

Sends data to the specified client asynchronously.

ValidateConfigurationString ( string configurationString ) : void

Validates the specified configurationString.

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

Метод Описание
AddUdpClient ( EndPoint udpClientEndPoint ) : TransportProvider
AddUdpClient ( string host, int port ) : void
IdentifyClient ( EndPoint remoteEndPoint ) : TransportProvider
ProcessReceive ( SocketAsyncEventArgs args ) : void

Callback method for asynchronous receive operation of payload data from any endpoint.

ProcessSend ( SocketAsyncEventArgs args ) : void

Callback method for asynchronous send operation.

ReceivePayloadAsync ( SocketAsyncEventArgs args ) : void

Initiate method for asynchronous receive operation of payload data from any endpoint.

SendPayload ( UdpServerPayload payload ) : void

Loops waiting for payloads and sends them on the socket.

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

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

Disconnects the specified connected client.
Client does not exist for the specified .
public DisconnectOne ( System.Guid clientID ) : void
clientID System.Guid ID of the client to be disconnected.
Результат void

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

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

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

Raises the ServerBase.ReceiveClientDataException event.
protected OnReceiveClientDataException ( System.Guid clientID, Exception ex ) : void
clientID System.Guid ID of client to send to event.
ex System.Exception Exception to send to event.
Результат void

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

Raises the ServerBase.SendClientDataException event.
protected OnSendClientDataException ( System.Guid clientID, Exception ex ) : void
clientID System.Guid ID of client to send to event.
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 ServerBase.ReceiveClientData event handler. Calling this method outside this event will have unexpected results.
/// No received data buffer has been defined to read -or- /// Specified does not exist, cannot read buffer. /// is null. /// or is less than 0 -or- /// and will exceed length. ///
public Read ( System.Guid clientID, byte buffer, int startIndex, int length ) : int
clientID System.Guid ID of the client from which data buffer should be read.
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 TcpServer settings to the config file if the ServerBase.PersistSettings property is set to true.
public SaveSettings ( ) : void
Результат void

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

Sends data to the specified client asynchronously.
protected SendDataToAsync ( System.Guid clientID, byte data, int offset, int length ) : WaitHandle
clientID System.Guid ID of the client to which the data is to be sent.
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 .
Результат System.Threading.WaitHandle

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

Starts the UdpServer synchronously and begins accepting client connections asynchronously.
Attempt is made to the when it is running.
public Start ( ) : void
Результат void

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

Stops the UdpServer synchronously and disconnects all connected clients.
public Stop ( ) : void
Результат void

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

Gets the TransportProvider{EndPoint} object associated with the specified client ID.
Client does not exist for the specified .
public TryGetClient ( System.Guid clientID, TransportProvider &udpClient ) : bool
clientID System.Guid ID of the client.
udpClient TransportProvider The UDP client.
Результат bool

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

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

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

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

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

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

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

Validates the specified configurationString.
Port property is missing. Port property value is not between and .
protected ValidateConfigurationString ( string configurationString ) : void
configurationString string Configuration string to be validated.
Результат void