public class UdpClient : ClientBase
Public Class UdpClient
Inherits ClientBase
public ref class UdpClient : public ClientBase
Gemstone.Communication.UdpClient = function();
Type.createClass(
'Gemstone.Communication.UdpClient',
Gemstone.Communication.ClientBase);
Use UdpClient when the primary purpose is to receive data.
The Client socket can be bound to a specified interface on a machine with multiple interfaces by specifying the interface in the ConnectionString (Example: "Server=localhost:8888; Port=8989; Interface=127.0.0.1")
The Client socket can be used just for transmitting data without being bound to a local interface by specifying -1 for the port number in the ConnectionString (Example: "Server=localhost:8888; Port=-1")
using System;
using GSF;
using GSF.Communication;
using GSF.Security.Cryptography;
using GSF.IO.Compression;
class Program
{
static UdpClient s_client;
static void Main(string[] args)
{
// Initialize the client.
s_client = new UdpClient("Server=localhost:8888; Port=8989");
s_client.Handshake = false;
s_client.ReceiveTimeout = -1;
s_client.Encryption = CipherStrength.None;
s_client.Compression = CompressionStrength.NoCompression;
s_client.SecureSession = false;
s_client.Initialize();
// Register event handlers.
s_client.ConnectionAttempt += s_client_ConnectionAttempt;
s_client.ConnectionEstablished += s_client_ConnectionEstablished;
s_client.ConnectionTerminated += s_client_ConnectionTerminated;
s_client.ReceiveDataComplete += s_client_ReceiveDataComplete;
// Connect the client.
s_client.Connect();
// Transmit user input to the server.
string input;
while (string.Compare(input = Console.ReadLine(), "Exit", true) != 0)
{
s_client.Send(input);
}
// Disconnect the client on shutdown.
s_client.Dispose();
}
static void s_client_ConnectionAttempt(object? sender, EventArgs e)
{
Console.WriteLine("Client is connecting to server.");
}
static void s_client_ConnectionEstablished(object? sender, EventArgs e)
{
Console.WriteLine("Client connected to server.");
}
static void s_client_ConnectionTerminated(object? sender, EventArgs e)
{
Console.WriteLine("Client disconnected from server.");
}
static void s_client_ReceiveDataComplete(object? sender, EventArgs<byte[], int> e)
{
Console.WriteLine(string.Format("Received data - {0}.", s_client.TextEncoding.GetString(e.Argument1, 0, e.Argument2)));
}
}
UdpClient | Initializes a new instance of the UdpClient class. |
UdpClient(String) | Initializes a new instance of the UdpClient class. |
AllowDualStackSocket | Gets or sets a boolean value that determines if dual-mode socket is allowed when endpoint address is IPv6. |
Client | Gets the Socket object for the UdpClient. |
ConnectionString |
Gets or sets the data required by the client to connect to the server.
(Inherited from ClientBase) |
ConnectionTime |
Gets the Time for which the client has been connected to the server.
(Inherited from ClientBase) |
CurrentState |
Gets the current ClientState.
(Inherited from ClientBase) |
Enabled |
Gets or sets a boolean value that indicates whether the client is currently enabled.
(Inherited from ClientBase) |
IsDisposed |
Gets a flag that indicates whether the object has been disposed.
(Inherited from ClientBase) |
MaxConnectionAttempts |
Gets or sets the maximum number of times the client will attempt to connect to the server.
(Inherited from ClientBase) |
MaxPacketSize | Gets or sets the maximum expected size for packets being received by this UdpClient. |
MaxSendQueueSize | Gets or sets the maximum size for the send queue before payloads are dumped from the queue. |
Name |
Gets or sets the unique identifier of the server.
(Inherited from ClientBase) |
ReadIndex |
Gets or sets current read index for received data buffer incremented at each Read(Byte, Int32, Int32) call.
(Inherited from ClientBase) |
ReceiveBufferSize |
Gets or sets the size of the buffer used by the client for receiving data from the server.
(Overrides ClientBaseReceiveBufferSize) |
ReceivePacketInfo | Gets or sets the flag that determines whether the UDP client should attempt to receive packet info when receiving data from the socket. |
SendBufferSize |
Gets or sets the size of the buffer used by the client for sending data to the server.
(Inherited from ClientBase) |
ServerIndex |
Gets the current server index, when multiple server end points are defined.
(Inherited from ClientBase) |
ServerUri |
Gets the server URI of the UdpClient.
(Overrides ClientBaseServerUri) |
Statistics |
Gets the TransportStatistics for the client connection.
(Inherited from ClientBase) |
Status |
Gets the descriptive status of the client.
(Overrides ClientBaseStatus) |
TextEncoding |
Gets or sets the Encoding to be used for the text sent to the server.
(Inherited from ClientBase) |
TrackStatistics |
Determines whether the base class should track statistics.
(Overrides ClientBaseTrackStatistics) |
TransportProtocol |
Gets the TransportProtocol used by the client for the transportation of data with the server.
(Inherited from ClientBase) |
AddMulticastMembership | Adds a multicast membership to the UDP socket. |
Connect |
Connects the client to the server synchronously.
(Inherited from ClientBase) |
ConnectAsync |
Connects the UdpClient to the server asynchronously.
(Overrides ClientBaseConnectAsync) |
Disconnect |
Disconnects the UdpClient from the connected server synchronously.
(Overrides ClientBaseDisconnect) |
Dispose |
Releases all the resources used by the ClientBase object.
(Inherited from ClientBase) |
Dispose(Boolean) |
Releases the unmanaged resources used by the UdpClient and optionally releases the managed resources.
(Overrides ClientBaseDispose(Boolean)) |
DropMulticastMembership | Drops a multicast membership from the UDP socket. |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object) |
GetHashCode | Serves as the default hash function. (Inherited from Object) |
GetType | Gets the Type of the current instance. (Inherited from Object) |
Initialize |
Initializes the client.
(Inherited from ClientBase) |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object) |
OnConnectionAttempt |
Raises the ConnectionAttempt event.
(Inherited from ClientBase) |
OnConnectionEstablished |
Raises the ConnectionEstablished event.
(Inherited from ClientBase) |
OnConnectionException |
Raises the ConnectionException event.
(Overrides ClientBaseOnConnectionException(Exception)) |
OnConnectionTerminated |
Raises the ConnectionTerminated event.
(Overrides ClientBaseOnConnectionTerminated) |
OnReceiveData |
Raises the ReceiveData event.
(Inherited from ClientBase) |
OnReceiveDataComplete |
Raises the ReceiveDataComplete event.
(Inherited from ClientBase) |
OnReceiveDataException |
Raises the ReceiveDataException event.
(Overrides ClientBaseOnReceiveDataException(Exception)) |
OnSendDataComplete |
Raises the SendDataComplete event.
(Inherited from ClientBase) |
OnSendDataException |
Raises the SendDataException event.
(Overrides ClientBaseOnSendDataException(Exception)) |
OnSendDataStart |
Raises the SendDataStart event.
(Inherited from ClientBase) |
Read |
Reads a number of bytes from the current received data buffer and writes those bytes into a byte array at the specified offset.
(Overrides ClientBaseRead(Byte, Int32, Int32)) |
RequestNextServerIndex |
Requests that the client attempt to move to the next ServerIndex.
(Inherited from ClientBase) |
Send(Byte) |
Sends data to the server synchronously.
(Inherited from ClientBase) |
Send(String) |
Sends data to the server synchronously.
(Inherited from ClientBase) |
Send(Byte, Int32, Int32) |
Sends data to the server synchronously.
(Inherited from ClientBase) |
SendAsync(Byte) |
Sends data to the server asynchronously.
(Inherited from ClientBase) |
SendAsync(String) |
Sends data to the server asynchronously.
(Inherited from ClientBase) |
SendAsync(Byte, Int32, Int32) |
Sends data to the server asynchronously.
(Inherited from ClientBase) |
SendDataAsync |
Sends data to the server asynchronously.
(Overrides ClientBaseSendDataAsync(Byte, Int32, Int32)) |
SendDataToAsync | Sends data to the server asynchronously. |
ToString | Returns a string that represents the current object. (Inherited from Object) |
UpdateBytesReceived |
Updates the Statistics pertaining to bytes received.
(Inherited from ClientBase) |
UpdateBytesSent |
Updates the Statistics pertaining to bytes sent.
(Inherited from ClientBase) |
ValidateConnectionString |
Validates the specified connectionString.
(Overrides ClientBaseValidateConnectionString(String)) |
ConnectionAttempt |
Occurs when client is attempting connection to the server.
(Inherited from ClientBase) |
ConnectionEstablished |
Occurs when client connection to the server is established.
(Inherited from ClientBase) |
ConnectionException |
Occurs when an Exception is encountered during connection attempt to the server.
(Inherited from ClientBase) |
ConnectionTerminated |
Occurs when client connection to the server is terminated.
(Inherited from ClientBase) |
Disposed |
Occurs when the ClientBase has been disposed.
(Inherited from ClientBase) |
ReceiveData |
Occurs when unprocessed data has been received from the server.
(Inherited from ClientBase) |
ReceiveDataComplete |
Occurs when data received from the server has been processed and is ready for consumption.
(Inherited from ClientBase) |
ReceiveDataException |
Occurs when an Exception is encountered when receiving data from the server.
(Inherited from ClientBase) |
ReceiveDataFrom | Occurs when unprocessed data has been received from the server. |
ReceiveDataFromComplete | Occurs when data received from the server has been processed and is ready for consumption. |
SendDataComplete |
Occurs when the client has successfully sent data to the server.
(Inherited from ClientBase) |
SendDataException |
Occurs when an Exception is encountered when sending data to the server.
(Inherited from ClientBase) |
SendDataStart |
Occurs when the client begins sending data to the server.
(Inherited from ClientBase) |
DefaultAllowDualStackSocket | Specifies the default value for the AllowDualStackSocket property. |
DefaultConnectionString | Specifies the default value for the ConnectionString property. |
DefaultMaxPacketSize | Specifies the default value for the MaxPacketSize property. |
DefaultMaxSendQueueSize | Specifies the default value for the MaxSendQueueSize property. |
DefaultReceiveBufferSize | Specifies the default value for the ReceiveBufferSize property. |