我尝试在我的 measure.ts
中使用以下代码脚本:
Deno.DatagramConn.send(...)
当我像这样运行我的脚本时:deno run --unstable --allow-all measure.ts
我收到以下错误:Property 'DatagramConn' does not exist on type 'typeof Deno'. 'Deno.DatagramConn' is an
unstable API. Did you forget to run with the '--unstable' flag?
这个错误似乎同时否认和确认 Deno.DatagramConn
的存在。 API同样我试过
Deno.connect({transport : 'udp'})
但这给了我以下错误(这可能是有意义的,因为 UDP 是“无连接”的):Type '"udp"' is not assignable to type '"tcp"
最佳答案
我似乎已经想通了。我实际上需要先listen
在套接字上,然后在其上发送数据。
const addr : Deno.NetAddr = {transport: "udp", port: 8125, hostname: "1.2.3.4"};
const socket = await Deno.listenDatagram({
port: 0,
transport: "udp",
hostname: "0.0.0.0"
});
socket.send(new Uint8Array(), addr);
当您知道如何 ¯\_(ツ)_/¯
时,这很容易
关于udp - 如何在 Deno 中发送 UDP 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65205696/