通过无线网络在智能设备应用中接收udp [英] RECEIVE udp in smart device aplication via wireless network
本文介绍了通过无线网络在智能设备应用中接收udp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是代码
我无法理解问题
this is the code
and I can''t understand the problem
using System;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace SmartDeviceProject3
{
public partial class recv : Form
{
string mcastGroup, port;
Thread t;
public recv()
{
InitializeComponent();
t = new Thread(new ThreadStart(receive));
}
private void button1_Click(object sender, EventArgs e)
{
mcastGroup = "224.5.6.7";
port = "5000";
t.Start();
}
private void receive()
{
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, int.Parse(port));
s.Bind(ipep);
IPAddress ip = IPAddress.Parse(mcastGroup);
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ip, IPAddress.Any));
while (true)
{
byte[] b = new byte[10];
Console.WriteLine("Waiting for data..");
label1.Text = "Waiting for data .. ";
s.Receive(b);
string str = System.Text.Encoding.ASCII.GetString(b, 0, b.Length);
Console.WriteLine();
MessageBox.Show("RX: " + str.Trim());
textBox1.Text += str.Trim();
}
}
}
}
推荐答案
yasser_enpc写道:
yasser_enpc wrote:
这是代码
我无法理解问题
this is the code
and I can''t understand the problem
我们也不能!尝试用简单的术语进行解释.另外,请使用< pre></pre>标签以正确格式化您的代码;就像我上面所做的一样.这就是代码块"按钮在编辑窗口中的作用.
Neither can we! Try explaining it in simple terms. Also please use the <pre></pre> tags to format your code properly; like I did above. That is what the "code block" button is for in the edit window.
这篇关于通过无线网络在智能设备应用中接收udp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文