有奖捉虫:办公协同&微信生态&物联网文档专题 HOT
Option 是全局的配置参数,对于不同类型的请求可以设置不同的配置。

参数

参数
类型
描述
headers
Record<string,string>
请求头
protocol
 string
协议类型,支持 polling/websocket

样例

// SocketIO API
import socketio from 'pts/socketio';
import { check, sleep } from 'pts';
import util from 'pts/util';

export default function () {
const res = socketio.connect('http://localhost:8080', function (socket) {
socket.on('open', () => console.log('connected'));
socket.on('message', (data) => console.log('message received: ', data));
socket.on('binaryMessage', (data) => console.log('binaryMessage received: ', data));
socket.on('close', () => console.log('disconnected'));
socket.setTimeout(function () {
console.log('3 seconds passed, closing the socket');
socket.close();
}, 3000);
// 设置定时任务
socket.setTimeout(function () {
socket.emit('message', 'hello');
socket.emit('binaryMessage', util.base64Decoding('aGVsbG8=', 'std', 'b'));
socket.emit('ackMessage', 'hello ack', function(msg) {