sending a javascript object through websockets with faye

后端 未结 3 449
闹比i
闹比i 2020-12-12 22:12

Hi all I\'m trying to send a javascript object through websockets:

the faye-websockets documentation says:

send(message) accepts either

3条回答
  •  醉酒成梦
    2020-12-12 22:57

    Client:

    const bson = new BSON();
    ws.binaryType = 'arraybuffer';
    
    ws.onmessage = function(event) {
      console.log(bson.deserialize(Buffer.from(event.data)));
    }
    

    Server:

     const data = bson.serialize({ ... });
     ws.send(data);
    

提交回复
热议问题