Socket 广播与组播能否跨网段?
Socket 广播与组播能否跨网段,相关代码如下:
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPEndPoint iep = new IPEndPoint(IPAddress.Broadcast, Port);
byte[] data = Encoding.ASCII.GetBytes(Info);
sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
sock.SendTo(data, iep);
sock.Close();
只能同网段的可以收到数据,如果是跨网段则一定要指定IP
IPEndPoint iep = new IPEndPoint(“目标机器IP”, Port);
------解决方案--------------------跨不跨都需要指定IP终结点