美文网首页
微信小程序websocket使用protobuf

微信小程序websocket使用protobuf

作者: EasyNetCN | 来源:发表于2022-09-20 08:18 被阅读0次

在微信小程序中,websocket使用protobuf,需要注意两点:

1:心跳检测设置在30秒内,因为30无消息,会断掉链接
2:支持string和arraybuffer类型,所以把Uint8Array直接转换为arraybuffer

import * as proto from '@/lib/message.js';

const messagePB = proto.protocol.Message.create(this.sendObj)
const buffer = proto.protocol.Message.encode(messagePB).finish()

new Uint8Array([...buffer]).buffer

相关文章

网友评论

      本文标题:微信小程序websocket使用protobuf

      本文链接:https://www.haomeiwen.com/subject/pbdbortx.html