以hexa发送UDP包 [英] Send a UDP pack in hexa

查看:86
本文介绍了以hexa发送UDP包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。

我不会说英语,但我会尝试。

I dont speak english but i will try.

我正在尝试发送一个像这样的字符串" 02 00 05 FF"在udp上,这是一个控制系统灯的代码,我必须发送(在这种情况下)4个字节。我将从另一个程序中获取
string [] args 的字符串。

I am trying to send a string like this "02 00 05 FF" over a udp, this is a code for control a system light and i have to send (in this case) 4 bytes. I will get the string with string[] args from another program.

所以我创建了这个以发送udp:

So i creted this to send the udp:

            UdpClient udpClient = new UdpClient();

            IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(" 255.255.255.255"),myPort);

             byte [] bytes = Encoding.Default.GetBytes(myMessage);

            udpClient.Send(bytes,bytes.Length,endPoint);

            udpClient.Close();

            UdpClient udpClient = new UdpClient();
            IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("255.255.255.255"), myPort);
            byte[] bytes = Encoding.Default.GetBytes(myMessage);
            udpClient.Send(bytes, bytes.Length, endPoint);
            udpClient.Close();

但这不起作用,因为会对字符串进行编码。我只需要发送字符串的确切方式。那么我该如何发送准确的值"02 00 05 FF"呢? ?这只是一个例子,我有几个代码一个接一个地发送来控制我的系统灯(开,关,
场景,调光器等)。

But this dont work because will encode the string. I need only send the string exactly how it is. So how can i send the exactly value "02 00 05 FF" ? This is only a exemple, i have several codes to send, one by one, to control my system lights (on, off, scene, dimmers, etc).

谢谢我很抱歉我的英语不好。

Thanks and i am sorry for my bad english.

推荐答案

你需要发送电线上的字节0x02 0x00 0x05 0xFF或字符串"02 00 05 FF"?目前,您将字符串作为字节流0x30 0x32 0x20 0x30 0x30 0x20 0x30 0x35 0x20 0x46 0x46发送。使用

Do you need to send the bytes 0x02 0x00 0x05 0xFF over the wire or the string "02 00 05 FF"? Currently you are sending the string as byte stream 0x30 0x32 0x20 0x30 0x30 0x20 0x30 0x35 0x20 0x46 0x46. Use

 byte[] bytes = new byte[] { 0x02, 0x00, 0x05, 0xff };


来制作你的包。

to craft your packet.


这篇关于以hexa发送UDP包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆