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

Cannot receive Buffer in NodeJS server/client #3316

Closed
1 of 2 tasks
jacargentina opened this issue Aug 24, 2018 · 5 comments
Closed
1 of 2 tasks

Cannot receive Buffer in NodeJS server/client #3316

jacargentina opened this issue Aug 24, 2018 · 5 comments

Comments

@jacargentina
Copy link

jacargentina commented Aug 24, 2018

You want to:

  • report a bug
  • request a feature

Current behaviour

Emitting a Buffer is not working, the client is not receiving anything.

Steps to reproduce

  • git clone https://github.com/jacargentina/socket-test
  • cd socket-test
  • npm install
  • npm run test-fail

Also can do npm run test-pass which is exactly the same but emitting a string, which simply works!

Expected behaviour

Should just work

Setup

  • OS: macOS/Linux
  • socket.io version: 2.1.1
@jacargentina
Copy link
Author

@darrachequesne could u look at this please?

@darrachequesne
Copy link
Member

darrachequesne commented Aug 27, 2018

@jacargentina thanks for providing a way to reproduce, that really helps 👍

That looks reaaaaaally weird, I'm not able to reproduce within the fiddle: https://github.com/socketio/socket.io-fiddle/tree/issues-3316

// server-side
  socket:test starting server +0ms
  socket:test connection +4s /hub#VduhqmBscd9Z3sMsAAAA
  socket:test data response +6ms <Buffer 68 69 21>
// client-side
  socket:test starting client +0ms
  socket:test connected +73ms
  socket:test data +0ms <Buffer 68 65 6c 6c 6f 20 79 6f 75 21>

Hmm... could it be related to jest?

Edit: possibly related to jestjs/jest#3186

@jacargentina
Copy link
Author

@darrachequesne you're right with jest, replacing with mocha just works! At least i can go on with mocha, while jest team fixes this.

nnn-gif added a commit to EthVM/EthVM that referenced this issue Sep 6, 2018
skip events related to socketio/socket.io#3316
@efkan
Copy link
Contributor

efkan commented Dec 18, 2018

@jacargentina , @darrachequesne

I've spent three days to diagnosis this issue. Anyway..

Yes, Mocha testing works seamlessly and I also use Mocha when testing socket.io related code.

I've just realized that if server allowUpgrades option is set as false then Jest testing can be passed!

As a workaround allowUpgrades option can be set as false for testing like the following:

if (process.env.NODE_ENV === 'test') {
  io = require('socket.io')(server, {  allowUpgrades : false }); 
} else {
  // current socket constuction code
}

If the issue is the same as mine it must works.

Edit
Actually giving {upgrade: false} option to socket.io-client is more sense.

const socket = require('socket.io-client')(serverUrl, {upgrade: false});

@darrachequesne
Copy link
Member

Closed due to inactivity, please reopen if needed.

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