我在使用C#发送UDP数据的套接字时遇到问题 - 基本上套接字没有从网络上的其他计算机接收任何数据,直到首先通过套接字发送了一些数据
不确定为什么它表现得很奇怪,我希望你们能指出我正确的方向 - 代码示例在下面。
由于
- 丹
private Socket UDPSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPAddress bindIP = BindingIP;
if (bindIP == IPAddress.None)
throw new Exception("Error binding to network interface \"" + _mcinter + "\" - interface not found");
//recieve data from any source
IPEndPoint LocalHostIPEnd = new IPEndPoint(bindIP, Target_Port);
//init Socket properties:
UDPSocket.SetSocketOption(SocketOptionLevel.Udp, SocketOptionName.NoDelay, 1);
//allow for loopback testing
UDPSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
//extremly important to bind the Socket before joining multicast groups
UDPSocket.Bind(LocalHostIPEnd);
//get in waiting mode for data - always (this doesn't halt code execution)
UDPSocket.BeginReceiveFrom(...);
答案 0 :(得分:2)
没关系,修好了
故事的寓意是---总是检查防火墙是否已启用......