C#UDP广播发送和接收

C#UDP广播发送和接收

本文介绍了C#UDP广播发送和接收的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:

我正在尝试创建一个代码,将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:




Code Snippet

推荐答案

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广播发送和接收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 18:18