[英]Convert Datagram Data To String HEX
I'm Listening To UDP 6000 port and I want to convert incoming packages to Hex String我正在收听 UDP 6000 端口,我想将传入的包转换为十六进制字符串
I searched but nothing found我搜索但没有找到
Here is my code这是我的代码
import 'dart:io';
import 'package:udp/udp.dart';
main() async {
var sender = await UDP.bind(Endpoint.loopback(port: Port(42)));
var dataLength = await sender.send(
"Hello World!".codeUnits, Endpoint.broadcast(port: Port(21)));
stdout.write("${dataLength} bytes sent.");
var receiver =
await UDP.bind(Endpoint.unicast(InternetAddress.anyIPv4, Port(6000)));
await receiver.listen((datagram) {
print(datagram.data);
}, Duration(seconds: 200));
sender.close();
receiver.close();
}
#
my incoming package is like this:我传入的 package 是这样的:
[104, 101, 108, 108, 111] [104、101、108、108、111]
I want to Convert to this我想转换成这个
68656c6c6f 68656c6c6f
thanks谢谢
You can use the toRadixString
to convert to values to hex, and the map the list.您可以使用
toRadixString
将值转换为十六进制,并使用 map 列表。
var hex = datagram.data.map((e) => e.toRadixString(16));
print(hex);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.