id 0x00 name发过去不就行了
自己定义发包格式想怎么取怎么取
不要问具体代码
这个范围太大

解决方案 »

  1.   

    struct 和class的唯一区别是一个是值类型,一个是引用类型,这个很简单吧
      

  2.   

    using System;
    using System.Net;
    using System.Net.Sockets;
    using System.Text;public struct Hello
    {
       int id;
       string name;
       byte[] Serialize()
       {
         ...序列化成二进制;
       };
       void DeSerialize(byte[])
       {
        ...反序列化;
       };
    }public class UDPListener 
    {
        private const int listenPort = 11000;
        
        private static void StartListener() 
        {
            bool done = false;
            
            UdpClient listener = new UdpClient(listenPort);
            IPEndPoint groupEP = new IPEndPoint(IPAddress.Any,listenPort);
        Hello a = new Hello;        try 
            {
                while (!done) 
                {
                    Console.WriteLine("Waiting for broadcast");
                    byte[] bytes = listener.Receive( ref groupEP);
            a.DeSerialize(bytes);
                    Console.WriteLine("Received broadcast from {0} :\n {1}\n",
                        groupEP.ToString(),
                        Encoding.ASCII.GetString(bytes,0,bytes.Length));
                }
                
            } 
            catch (Exception e) 
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                listener.Close();
            }
        }    public static int Main() 
        {
            StartListener();        return 0;
        }
    }