Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server cannot receives Uint8Array from client, it only receives a plain Object #3143

Closed
1 of 2 tasks
Meigyoku-Thmn opened this issue Dec 21, 2017 · 2 comments
Closed
1 of 2 tasks

Comments

@Meigyoku-Thmn
Copy link

Meigyoku-Thmn commented Dec 21, 2017

You want to:

  • report a bug
  • request a feature

Current behaviour

Server cannot receives Uint8Array from client, it only receives a plain Object.

Steps to reproduce (if the current behaviour is a bug)

Client side:

let binary = new Uint8Array(5);
binary.fill(12);
socket.emit('binary', binary);

Server side:

socket.on('binary', (binaryData) => {
   console.log(binaryData);
});

Result of console.log on Server side:

{ '0': 12,
  '1': 12,
  '2': 12,
  '3': 12,
  '4': 12,
  '5': 12 }

Expected behaviour

Server side receives a Buffer, an ArrayBuffer, or Uint8Array.

Setup

  • OS: Windows 10
  • browser: Google Chrome and Mozilla Firefox, Nodejs v8.9.1
  • socket.io version: 2.0.4

Other information (e.g. stacktraces, related issues, suggestions how to fix)

I don't know if this is a bug or not.
Edit: Reason to do this: to save bandwidth.

@byrgazov
Copy link

byrgazov commented Jan 27, 2018

let binary = new Uint8Array(5);
binary.fill(12);
let buffer = binary.buffer.slice(binary.byteOffset, binary.byteOffset + binary.byteLength);
socket.emit('binary', buffer);
const toArrayBuffer = require('to-arraybuffer');

let binary = new Uint8Array(5);
binary.fill(12);
let buffer = toArrayBuffer(binary);
socket.emit('binary', buffer);

@darrachequesne
Copy link
Member

This was fixed by socketio/socket.io-parser@8822578, included in socket.io-parser@3.1.3 & socket.io@2.0.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants