# mt.createUDPSocket()

创建一个 UDP Socket 实例。

# 支持情况

项 说明
兼容性 部分兼容

# 参数

无参数。

# 返回值

返回 UDPSocket 对象。

# 示例代码

const udp = mt.createUDPSocket()
const port = udp.bind(0)
console.log('已绑定端口:', port)

udp.onMessage((res) => {
  console.log('收到数据:', res.message)
  console.log('来自:', res.remoteInfo.address, ':', res.remoteInfo.port)
})

udp.send({
  address: '192.168.1.100',
  port: 8080,
  message: new ArrayBuffer(10)
})

# 与微信差异

不支持微信基础库 2.18.0 新增的 type 参数(udp4/udp6),固定使用 udp4。

上次更新: 8/10/2026, 5:36:37 PM