问题描述
大家好:
我正在尝试创建一个代码,将LAN上的UDP消息广播到设备并接收广播回复。我已经能够成功地广播消息并查看广播响应。问题是我无法捕获广播响应。我正在从255.255.255.255端口15000发送广播消息。我也试图听这个相同的端口进行广播响应而没有运气。这就像我在听错了端口或其他东西。这是我的代码:
I am trying to create a code that will broadcast UDP messages across my LAN to devices and receive the broadcast replies. I have been able to successfully broadcast messages and see the broadcast response. The problem is that i can't capture the broadcast response. I am sending the broadcast messages from 255.255.255.255 port 15000. I am also trying to listen to this same port for broadcast responses with no luck. It's like i'm listening on the wrong port or something. Here is my code:
推荐答案
string returnData =编码。 ASCII.GetString(receiveBytes);
string returnData = Encoding.ASCII.GetString(receiveBytes);
到
string returnData = Encoding.ASCII.GetString(receiveBytes,0 ,receiveBytes.Length);
udp.Close();
udp.Close();
这篇关于C#UDP广播发送和接收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!