Version: 4.4.1.3
Enhances .NET with classes for DNS, servers and connection management.  Includes SSL security!

Windows Forms UDP Multicast Code Example

The following example demonstrates a UDP session in a Windows Forms environment. The app joins a multicast group, sends a message, receives a response and leaves. The session is executed asynchronously, without blocking the UI.

< Back to all samples for PowerTCP Sockets for .NET

private void buttonHello_Click(object sender, EventArgs e)
{
    //This application has a User-Interface, which we do not want to block.
    //Start launches the specified method on a worker thread.
    udp1.Start(sendHello, new Dart.Sockets.IPEndPoint("234.5.6.7", 59877));
}

private void sendHello(object groupEP)
{
    //Join a multicast group, send a message, receive a response, and leave.
    //The group endpoint is passed into the function.
    Dart.Sockets.IPEndPoint ep = (Dart.Sockets.IPEndPoint)groupEP;

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

    //Send message.
    udp1.Send("hello world", ep);

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

    //Leave group.
    udp1.LeaveMulticastGroup(ep.Address);
}