在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
发送端: Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPEndPoint iep = new IPEndPoint(IPAddress.Parse("224.0.0.1"), 3000); EndPoint ep = (EndPoint)iep; byte[] b = Encoding.ASCII.GetBytes("just a test!"); s.SendTo(b, ep); s.Close(); 接收端: Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPEndPoint iep = new IPEndPoint(IPAddress.Any, 3000); EndPoint ep=(EndPoint)iep; s.Bind(iep); s.SetSocketOption(SocketOptionLevel.IP,SocketOptionName.AddMembership,new MulticastOption(IPAddress.Parse("224.0.0.1"))); byte[]b=new byte[1024]; s.ReceiveFrom(b,ref ep); string test; test = System.Text.Encoding.ASCII.GetString(b); Console.WriteLine(test); s.Close(); Console.ReadKey(); |
请发表评论