In an effort to be able to send binary data while utilizing Socket.IO's RPC functionality, I thought that I could use both Socket.IO and the WS module on the same server. Rather than opening up completely separate servers to make both connections, I am wondering if I can utilize the same HTTP server.
Is it possible to use only one server created with http.createServer() for both Socket.IO and WS at the same time? To be clear, I anticipate creating both a Socket.IO connection and a regular WebSocket connection from the client. The following code creates protocol errors on the client side, presumably because both Socket.IO and WS are attempting to handle the connection.
var http = require('http');
var server = http.createServer(app);
server.listen(3000);
// Socket.IO
var io = require('socket.io').listen(server);
io.sockets.on('connection', function (socket) {
// ...
}
// ws
var WebSocketServer = require('ws').Server
var wss = new WebSocketServer({server: server});
wss.on('connection', function (ws) {
// ...
}