如何发送二进制数据?

问题描述 投票:2回答:2

我正在使用Mosquito MQTT服务器来广播消息,如何发送二进制数据(不是文本)?

我如何发送二进制数据(不是文本)?

例子:

mosquitto_pub -t test -m 0x452343

应该接收到的是:

0100 0101 0010 011 0100 0011
mqtt mosquitto
2个回答
8
投票

你可以把你的二进制数据放在一个文件中,然后把这个文件作为消息发送。

mosquitto_pub -t test -f file

或者你可以用libmosquitto或者其他MQTT客户端库来写你自己的客户端.


8
投票

如果你真的想发送二进制的字符序列,那么你可以使用echo将字符串转换为二进制。

echo -ne "\x45\x23\x43" | mosquitto_pub -h test.mosquitto.org -t 'test/binary' -s

这也适用于二进制命令的输出,比如在Raspberry Pi上捕捉图像。

raspistill -o - | mosquitto_pub -h test.mosquitto.org -t 'webcam/' -s
© www.soinside.com 2019 - 2024. All rights reserved.