Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

C# Programmation Réseau: Exemple d’un Serveur de diffusion avec le protocole UDP

 
 
 
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
 
public class Broadcst
{
   public static void Main()
   {
      Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
      IPEndPoint iep1 = new IPEndPoint(IPAddress.Broadcast9050);
      IPEndPoint iep2 = new IPEndPoint(IPAddress.Parse("192.168.1.255")9050);
 
      string hostname = Dns.GetHostName();
      byte[] data = Encoding.ASCII.GetBytes(hostname);
 
      sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast1);
      sock.SendTo(data, iep1);
      sock.SendTo(data, iep2);
      sock.Close();
   }
}
 
           
       

No comments yet.

Leave a Comment