let webSocketObject = null;
const connect = async uuid => new Promise((resolve, reject) => {
webSocketObject = uni.connectSocket({
url: 'wss://***:8080/wss',
header: {
UUID: uuid,
},
success: resolve,
fail: reject
})
webSocketObject.onOpen(res => {
console.log('链接成功')
console.log(res);
console.log(res.header);
console.log(res.data ?? '');
})
webSocketObject.onClose(res => {
console.log('连接关闭')
console.log(res);
})
webSocketObject.onError(res => {
console.log('连接错误')
console.log(res);
})
webSocketObject.onMessage(res => {
console.log('收到服务器内容:');
console.log(res.data);
})
})
uni.onSocketMessage(res => {
console.log('收到服务器内容:');
console.log(res.data);
})
uni.onSocketOpen(res => {
console.log('链接成功')
console.log(res);
console.log(res.header);
console.log(res.data ?? '');
})
uni.onSocketError(res => {
console.log('连接错误')
console.log(res);
})
uni.onSocketClose(res => {
console.log('连接关闭')
console.log(res);
})
2***@qq.com
- 发布:2024-01-22 14:51
- 更新:2024-01-22 14:51
- 阅读:224
0 个回复