gpt4 book ai didi

udp - 如何在 Deno 中发送 UDP 数据?

转载 作者:行者123 更新时间:2023-12-04 01:09:54 28 4
gpt4 key购买 nike

我尝试在我的 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com