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

Initialize the WebSocket server in the Server constructor #476

Merged

Conversation

lpinca
Copy link
Contributor

@lpinca lpinca commented Jan 26, 2017

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • other

Current behaviour

Described in #473.

New behaviour

Makes a plain Engine.IO server, not bound to any HTTP server, work again.

Other information (e.g. related issues)

Fixes #473.
It should also fix cases where an already listening server is used which is currently equally broken.

'use strict';

const eioc = require('engine.io-client');
const eio = require('engine.io');
const http = require('http');

const server = http.createServer();

server.listen(3000, () => {
  const engine = eio.attach(server);

  engine.on('connection', (socket) => {
    socket.on('message', (data) => socket.send(data));
    socket.on('close', () => console.log('close'));
  });

  const socket = eioc('http://localhost:3000');

  socket.on('open', () => socket.send('foo'));
  socket.on('message', (data) => console.log(data));
  socket.on('close', () => console.log('close'));
});

@darrachequesne
Copy link
Member

@lpinca thanks a lot!

@lpinca lpinca deleted the fix/websocket-server-initialization branch January 30, 2017 14:56
@darrachequesne darrachequesne added this to the 2.0.1 milestone Jan 30, 2017
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

Successfully merging this pull request may close these issues.

Cannot read property 'handleUpgrade' of undefined
2 participants