# UDPSocket.write(Object object)

向已通过 connect 连接的地址发送数据。

# 支持情况

项 说明
兼容性 部分兼容

# 语法

udpSocket.write(Object object)

# 参数

与 UDPSocket.send() 参数相同。

参数 类型 必填 说明
address string 否 目标地址(connect 后可省略)
port number 否 目标端口(connect 后可省略)
message string / ArrayBuffer 是 要发送的数据
offset number 否 数据的偏移量(仅 message 为 ArrayBuffer 时有效)
length number 否 数据的长度(仅 message 为 ArrayBuffer 时有效)

# 返回值

void。

# 注意事项

  • 调用前需先调用 connect 建立连接目标,否则需传入 address 和 port。

# 示例代码

udpSocket.connect({ address: '192.168.1.100', port: 8080 })

udpSocket.write({
  message: new ArrayBuffer(16)
})

# 与微信差异

  • 不支持微信的 setBroadcast 参数(广播模式)。
上次更新: 8/10/2026, 5:36:37 PM