PowerTCP Sockets for .NET

from $349.00
Available Platforms
<

UDP Multicast Code Example

See all PowerTCP Sockets for .NET Samples and Code Examples

 

The following C# example demonstrates a UDP session in a console environment. The app joins a multicast group, sends a message, receives a response and leaves.

 

Udp udp1 = new Udp();
string groupEpAddress = "234.5.6.7";
int groupEpPort = 59877;
string message = "hello world";

Dart.Sockets.IPEndPoint groupEp = new Dart.Sockets.IPEndPoint(groupEpAddress, groupEpPort);

//Join Multicast group.
udp1.Open(groupEp.Port);
udp1.JoinMulticastGroup(groupEp.Address);

//Send message.
Console.WriteLine("Sending: {0}", message);
udp1.Send(message, groupEp);

//Receive response.
byte[] buffer = new byte[1024];
Datagram response = udp1.Receive(buffer);

//Leave group.
udp1.LeaveMulticastGroup(groupEp.Address);

Console.WriteLine("Received: {0}", response.ToString());
Console.WriteLine("Press <Enter> to exit.");
Console.ReadLine(); 

To download a trial please visit the PowerTCP Sockets for .NET product page.