Socket.sendBinary(data)
注意
存在一个 API 更好、更标准的模块。
新的 k6/experimental/websockets API 部分实现了 WebSockets API 标准(living standard)。
如果可能,建议使用新的 API。它使用全局事件循环,以与其他 k6 API 保持一致,并获得更好的性能。
通过连接发送二进制数据。
参数 | 类型 | 描述 |
---|---|---|
data | ArrayBuffer | 要发送的数据。 |
示例
import ws from 'k6/ws';
const binFile = open('./file.pdf', 'b');
export default function () {
ws.connect('http://wshost/', function (socket) {
socket.on('open', function () {
socket.sendBinary(binFile);
});
socket.on('binaryMessage', function (msg) {
// msg is an ArrayBuffer, so we can wrap it in a typed array directly.
new Uint8Array(msg);
});
});
}
- 另请参阅 Socket.send(data)