C# Class GSF.Communication.ServerBase

Inheritance: System.ComponentModel.Component, IServer, ISupportInitialize, IPersistSettings
Show file Open project: GridProtectionAlliance/gsf Class Usage Examples

Private Properties

Property Type Description
BeginInit void
EndInit void

Public Methods

Method Description
Create ( string configurationString ) : IServer

Create a communications server

Note that typical configuration string should be prefixed with a "protocol=tcp" or a "protocol=udp"

DisconnectAll ( ) : void

Disconnects all of the connected clients.

DisconnectOne ( System.Guid clientID ) : void

When overridden in a derived class, disconnects a connected client.

Initialize ( ) : void

Initializes the server.

Initialize() is to be called by user-code directly only if the server is not consumed through the designer surface of the IDE.

IsClientConnected ( System.Guid clientID ) : bool

Determines whether the given client is currently connected to the server.

LoadSettings ( ) : void

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

Multicast ( byte data ) : void

Sends data to all of the connected clients synchronously.

Multicast ( byte data, int offset, int length ) : void

Sends data to all of the connected clients synchronously.

Multicast ( object serializableObject ) : void

Sends data to all of the connected clients synchronously.

Multicast ( string data ) : void

Sends data to all of the connected clients synchronously.

MulticastAsync ( byte data ) : WaitHandle[]

Sends data to all of the connected clients asynchronously.

MulticastAsync ( byte data, int offset, int length ) : WaitHandle[]

Sends data to all of the connected clients asynchronously.

MulticastAsync ( object serializableObject ) : WaitHandle[]

Sends data to all of the connected clients asynchronously.

MulticastAsync ( string data ) : WaitHandle[]

Sends data to all of the connected clients asynchronously.

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

When overridden in a derived class, 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 ReceiveClientData event handler. Calling this method outside this event will have unexpected results.

SaveSettings ( ) : void

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

SendTo ( Guid clientID, byte data ) : void

Sends data to the specified client synchronously.

SendTo ( Guid clientID, byte data, int offset, int length ) : void

Sends data to the specified client synchronously.

SendTo ( Guid clientID, object serializableObject ) : void

Sends data to the specified client synchronously.

SendTo ( Guid clientID, string data ) : void

Sends data to the specified client synchronously.

SendToAsync ( Guid clientID, byte data ) : WaitHandle

Sends data to the specified client asynchronously.

SendToAsync ( Guid clientID, byte data, int offset, int length ) : WaitHandle

Sends data to the specified client asynchronously.

SendToAsync ( Guid clientID, object serializableObject ) : WaitHandle

Sends data to the specified client asynchronously.

SendToAsync ( Guid clientID, string data ) : WaitHandle

Sends data to the specified client asynchronously.

Start ( ) : void

When overridden in a derived class, starts the server.

Stop ( ) : void

When overridden in a derived class, stops the server.

Protected Methods

Method Description
Dispose ( bool disposing ) : void

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

OnClientConnected ( Guid clientID ) : void

Raises the ClientConnected event.

OnClientConnectingException ( Exception ex ) : void

Raises the ClientConnectingException event.

OnClientDisconnected ( Guid clientID ) : void

Raises the ClientDisconnected event.

OnReceiveClientData ( Guid clientID, int size ) : void

Raises the ReceiveClientData event.

This event is automatically raised by call to OnReceiveClientDataComplete so that inheritors never need to worry about raising this event. This method is only included here in case any custom server implementations need to explicitly raise this event.

OnReceiveClientDataComplete ( Guid clientID, byte data, int size ) : void

Raises the ReceiveClientDataComplete event.

OnReceiveClientDataException ( Guid clientID, Exception ex ) : void

Raises the ReceiveClientDataException event.

OnSendClientDataComplete ( Guid clientID ) : void

Raises the SendClientDataComplete event.

OnSendClientDataException ( Guid clientID, Exception ex ) : void

Raises the SendClientDataException event.

OnSendClientDataStart ( Guid clientID ) : void

Raises the SendClientDataStart event.

OnServerStarted ( ) : void

Raises the ServerStarted event.

OnServerStopped ( ) : void

Raises the ServerStopped event.

OnUnhandledUserException ( Exception ex ) : void

Raises the UnhandledUserException event.

ReStart ( ) : void

Re-starts the server if currently running.

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

When overridden in a derived class, sends data to the specified client asynchronously.

ServerBase ( ) : System

Initializes a new instance of the server.

ServerBase ( TransportProtocol transportProtocol, string configurationString ) : System

Initializes a new instance of the server.

ValidateConfigurationString ( string configurationString ) : void

When overridden in a derived class, validates the specified configurationString.

Private Methods

Method Description
BeginInit ( ) : void
EndInit ( ) : void

Method Details

Create() public static method

Create a communications server
Note that typical configuration string should be prefixed with a "protocol=tcp" or a "protocol=udp"
public static Create ( string configurationString ) : IServer
configurationString string The configuration string for the server.
return IServer

DisconnectAll() public method

Disconnects all of the connected clients.
public DisconnectAll ( ) : void
return void

DisconnectOne() public abstract method

When overridden in a derived class, disconnects a connected client.
public abstract DisconnectOne ( System.Guid clientID ) : void
clientID System.Guid ID of the client to be disconnected.
return void

Dispose() protected method

Releases the unmanaged resources used by the server 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.
return void

Initialize() public method

Initializes the server.
Initialize() is to be called by user-code directly only if the server is not consumed through the designer surface of the IDE.
public Initialize ( ) : void
return void

IsClientConnected() public method

Determines whether the given client is currently connected to the server.
public IsClientConnected ( System.Guid clientID ) : bool
clientID System.Guid The ID of the client.
return bool

LoadSettings() public method

Loads saved server settings from the config file if the PersistSettings property is set to true.
has a value of null or empty string.
public LoadSettings ( ) : void
return void

Multicast() public method

Sends data to all of the connected clients synchronously.
public Multicast ( byte data ) : void
data byte The binary data that is to be sent.
return void

Multicast() public method

Sends data to all of the connected clients synchronously.
public Multicast ( byte data, int offset, int length ) : void
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 .
return void

Multicast() public method

Sends data to all of the connected clients synchronously.
public Multicast ( object serializableObject ) : void
serializableObject object The serializable object that is to be sent.
return void

Multicast() public method

Sends data to all of the connected clients synchronously.
public Multicast ( string data ) : void
data string The plain-text data that is to be sent.
return void

MulticastAsync() public method

Sends data to all of the connected clients asynchronously.
public MulticastAsync ( byte data ) : WaitHandle[]
data byte The binary data that is to be sent.
return WaitHandle[]

MulticastAsync() public method

Sends data to all of the connected clients asynchronously.
public MulticastAsync ( 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 .
return WaitHandle[]

MulticastAsync() public method

Sends data to all of the connected clients asynchronously.
public MulticastAsync ( object serializableObject ) : WaitHandle[]
serializableObject object The serializable object that is to be sent.
return WaitHandle[]

MulticastAsync() public method

Sends data to all of the connected clients asynchronously.
public MulticastAsync ( string data ) : WaitHandle[]
data string The plain-text data that is to be sent.
return WaitHandle[]

OnClientConnected() protected method

Raises the ClientConnected event.
protected OnClientConnected ( Guid clientID ) : void
clientID Guid ID of client to send to event.
return void

OnClientConnectingException() protected method

Raises the ClientConnectingException event.
protected OnClientConnectingException ( Exception ex ) : void
ex Exception The encountered when connecting to the client.
return void

OnClientDisconnected() protected method

Raises the ClientDisconnected event.
protected OnClientDisconnected ( Guid clientID ) : void
clientID Guid ID of client to send to event.
return void

OnReceiveClientData() protected method

Raises the ReceiveClientData event.
This event is automatically raised by call to OnReceiveClientDataComplete so that inheritors never need to worry about raising this event. This method is only included here in case any custom server implementations need to explicitly raise this event.
protected OnReceiveClientData ( Guid clientID, int size ) : void
clientID Guid ID of the client from which data is received.
size int Number of bytes received from the client.
return void

OnReceiveClientDataComplete() protected method

Raises the ReceiveClientDataComplete event.
protected OnReceiveClientDataComplete ( Guid clientID, byte data, int size ) : void
clientID Guid ID of the client from which data is received.
data byte Data received from the client.
size int Number of bytes received from the client.
return void

OnReceiveClientDataException() protected method

Raises the ReceiveClientDataException event.
protected OnReceiveClientDataException ( Guid clientID, Exception ex ) : void
clientID Guid ID of client to send to event.
ex Exception Exception to send to event.
return void

OnSendClientDataComplete() protected method

Raises the SendClientDataComplete event.
protected OnSendClientDataComplete ( Guid clientID ) : void
clientID Guid ID of client to send to event.
return void

OnSendClientDataException() protected method

Raises the SendClientDataException event.
protected OnSendClientDataException ( Guid clientID, Exception ex ) : void
clientID Guid ID of client to send to event.
ex Exception Exception to send to event.
return void

OnSendClientDataStart() protected method

Raises the SendClientDataStart event.
protected OnSendClientDataStart ( Guid clientID ) : void
clientID Guid ID of client to send to event.
return void

OnServerStarted() protected method

Raises the ServerStarted event.
protected OnServerStarted ( ) : void
return void

OnServerStopped() protected method

Raises the ServerStopped event.
protected OnServerStopped ( ) : void
return void

OnUnhandledUserException() protected method

Raises the UnhandledUserException event.
protected OnUnhandledUserException ( Exception ex ) : void
ex Exception Exception to send to event.
return void

ReStart() protected method

Re-starts the server if currently running.
protected ReStart ( ) : void
return void

Read() public abstract method

When overridden in a derived class, 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 ReceiveClientData event handler. Calling this method outside this event will have unexpected results.
public abstract Read ( Guid clientID, byte buffer, int startIndex, int length ) : int
clientID 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 .
return int

SaveSettings() public method

Saves server settings to the config file if the PersistSettings property is set to true.
has a value of null or empty string.
public SaveSettings ( ) : void
return void

SendDataToAsync() protected abstract method

When overridden in a derived class, sends data to the specified client asynchronously.
protected abstract SendDataToAsync ( Guid clientID, byte data, int offset, int length ) : WaitHandle
clientID 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 .
return WaitHandle

SendTo() public method

Sends data to the specified client synchronously.
public SendTo ( Guid clientID, byte data ) : void
clientID Guid ID of the client to which the data is to be sent.
data byte The binary data that is to be sent.
return void

SendTo() public method

Sends data to the specified client synchronously.
public SendTo ( Guid clientID, byte data, int offset, int length ) : void
clientID 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 .
return void

SendTo() public method

Sends data to the specified client synchronously.
public SendTo ( Guid clientID, object serializableObject ) : void
clientID Guid ID of the client to which the data is to be sent.
serializableObject object The serializable object that is to be sent.
return void

SendTo() public method

Sends data to the specified client synchronously.
public SendTo ( Guid clientID, string data ) : void
clientID Guid ID of the client to which the data is to be sent.
data string The plain-text data that is to be sent.
return void

SendToAsync() public method

Sends data to the specified client asynchronously.
public SendToAsync ( Guid clientID, byte data ) : WaitHandle
clientID Guid ID of the client to which the data is to be sent.
data byte The binary data that is to be sent.
return WaitHandle

SendToAsync() public method

Sends data to the specified client asynchronously.
public SendToAsync ( Guid clientID, byte data, int offset, int length ) : WaitHandle
clientID 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 .
return WaitHandle

SendToAsync() public method

Sends data to the specified client asynchronously.
public SendToAsync ( Guid clientID, object serializableObject ) : WaitHandle
clientID Guid ID of the client to which the data is to be sent.
serializableObject object The serializable object that is to be sent.
return WaitHandle

SendToAsync() public method

Sends data to the specified client asynchronously.
public SendToAsync ( Guid clientID, string data ) : WaitHandle
clientID Guid ID of the client to which the data is to be sent.
data string The plain-text data that is to be sent.
return WaitHandle

ServerBase() protected method

Initializes a new instance of the server.
protected ServerBase ( ) : System
return System

ServerBase() protected method

Initializes a new instance of the server.
protected ServerBase ( TransportProtocol transportProtocol, string configurationString ) : System
transportProtocol TransportProtocol One of the values.
configurationString string The data used by the server for initialization.
return System

Start() public abstract method

When overridden in a derived class, starts the server.
public abstract Start ( ) : void
return void

Stop() public abstract method

When overridden in a derived class, stops the server.
public abstract Stop ( ) : void
return void

ValidateConfigurationString() protected abstract method

When overridden in a derived class, validates the specified configurationString.
protected abstract ValidateConfigurationString ( string configurationString ) : void
configurationString string The configuration string to be validated.
return void