Udp Multi-send : Socket Udp Client « Network « C# / CSharp Tutorial






using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

class MainClass
{
   public static void Main()
   {
      Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
      IPEndPoint iep = new IPEndPoint(IPAddress.Any, 9888);
      IPEndPoint iep2 = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9999);
      server.Bind(iep);
      
      byte[] data = Encoding.ASCII.GetBytes("This is a test message");
      server.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse("127.0.0.1")));
      server.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 50);
      server.SendTo(data, iep2);
      server.Close();
   }
}








33.11.Socket Udp Client
33.11.1.Simple Udp Client: send and receive
33.11.2.Udp client setup
33.11.3.Udp Multi-send