# ks.connectSocket

更新时间:2024-12-09 11:57:47

基础库1.26.1开始支持,低版本需做兼容处理

开发者工具1.22.0开始支持

创建一个 WebSocket 连接。

使用前请注意阅读相关说明 (opens new window)

# 参数

# Object object

属性 类型 默认值 必填 说明
url string 开发者服务器 wss 接口地址
header Object HTTP Header,Header 中不能设置 Referer
protocols Array 子协议数组
timeout number 超时时间,单位为毫秒
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数
complete function 接口调用结束的回调函数(调用成功、失败都会执行)

# 返回值

# SocketTask

WebSocket 任务

# 错误信息

错误信息 错误说明
websocket has up to max count:5 同时连接数超限

# 示例代码

ks.connectSocket({
    url: 'wss://example.qq.com',
    header: {
        'content-type': 'application/json'
    },
    protocols: ['protocol1']
})
Copyright ©2025, All Rights Reserved