发送数据
将模拟数据发送到原始 WebSocket 服务器。
通过调用 server.connect()
建立实际的服务器连接后,事件处理程序就可以开始通过 server.send()
方法向原始服务器发送模拟数据。
¥Once you establish the actual server connection by calling server.connect()
, your event handler can start sending mock data to the original server via the server.send()
method.
api.addEventListener('connection', ({ server }) => {
server.connect()
server.send('hello world')
})
server.send()
的调用签名和支持的数据类型与client.send()
相同。¥
server.send()
has the same call signature as supported data types asclient.send()
.
这对于通过模拟客户端发送的事件(包括客户端尚未发送的事件)来触发特定的服务器行为非常方便。
¥This is handy for triggering a particular server behavior by emulating a client-sent event (including those the client hasn’t sent).
API 参考
¥API reference
server.send()
The `server.send()` API reference.