UdpClient Members
Provides User Datagram Protocol (UDP) network services.
The UdpClient type exposes the following members.
| Name | Description | |
|---|---|---|
|
BeginReceive | Receives a datagram from a remote host asynchronously. |
|
BeginSend | Overloaded. Sends a datagram to a remote host asynchronously. |
|
Close | Closes the UDP connection. |
|
Connect | Overloaded. Establishes a default remote host. |
|
Dispose | Releases the unmanaged resources used by the UdpClient and optionally releases the managed resources. |
|
DropMulticastGroup | Overloaded. Leaves a multicast group. |
|
EndReceive | Ends a pending asynchronous receive. |
|
EndSend | Ends a pending asynchronous send. |
|
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 a hash function for a particular type. (Inherited from Object.) |
|
GetType | Gets the type of the current instance. (Inherited from Object.) |
|
JoinMulticastGroup | Overloaded. Adds a UdpClient to a multicast group. |
|
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
|
Receive | Returns a UDP datagram that was sent by a remote host. |
|
Send | Overloaded. Sends a UDP datagram to a remote host. |
|
ToString | Returns a string that represents the current object. (Inherited from Object.) |
| Name | Description | |
|---|---|---|
|
Active | Gets or sets a value indicating whether a default remote host has been established. |
|
Available | Gets the amount of data received from the network that is available to read. |
|
Client | Gets or sets the underlying network Socket. |
|
DontFragment | Gets or sets a Boolean value that specifies whether the UdpClient allows Internet Protocol (IP) datagrams to be fragmented. |
|
EnableBroadcast | Gets or sets a Boolean value that specifies whether the UdpClient may send or receive broadcast packets. |
|
ExclusiveAddressUse | Gets or sets a Boolean value that specifies whether the UdpClient allows only one client to use a port. |
|
MulticastLoopback | Gets or sets a Boolean value that specifies whether outgoing multicast packets are delivered to the sending application. |
|
Ttl | Gets or sets a value that specifies the Time to Live (TTL) value of Internet Protocol (IP) packets sent by the UdpClient. |
| Name | Description | |
|---|---|---|
|
IDisposable.Dispose | Infrastructure. Releases all resources used by the UdpClient. |
The use of the Receive method has one or more options that are not covered in the main page. The following demonstrates one use of the Receive method. Readers are encouraged to provide more examples.
const int listenPort = 11000;
string received_data;
byte[] receive_byte_array;
// Note that the constructor accepts the port number as an argument.
UdpClient listener = new UdpClient(listenPort);
// This prepares to listen for a UDP broadcast on any IP address but only on the port specified.
IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);
// Next we make a blocking call and wait for received data.
receive_byte_array = listener.Receive( ref groupEP );
// If the data is ASCII text, it must be converted before being used as text.
received_data = Encoding.ASCII.GetString(receive_byte_array, 0, receive_byte_array.Length);