You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The API allows implementing multiple sub-protocols in the socket call back using a switch on socket.ws.protocol to give the different protocols different socket event call-backs. It seems it would be nicer to make the server API look more like the browser's WS API, where the protocol is specified in the connection parameters, and you get different connection objects for different sub-protocols on the same server/port.
So:
var ws = require('websocket.io')
, one_server = ws.listen(3000, 'one_protocol')
, another_server = ws.listen(3000, 'another_protocol')
one_server.on('connection', function (socket) {
socket.on('message', function () { });
socket.on('close', function () { });
});
another_server.on('connection', function (socket) {
socket.on('message', function () { });
socket.on('close', function () { });
});
Instead of:
var ws = require('websocket.io')
, server = ws.listen(3000)
server.on('connection', function (socket) {
switch (socket.ws.protocol) {
case ('one_protocol'):
socket.on('message', function () { });
socket.on('close', function () { });
break;
case ('another_protocol'):
socket.on('message', function () { });
socket.on('close', function () { });
break;
});
Or maybe there is a better way of doing this that I've missed?
Its a fairly minor and probably mostly aesthetic issue. Still a "sanctioned" way of supporting multiple protocols on the same port should really be included in the examples, since its not obvious from the API. There are few examples of using multiple WS sub-protocols on-line at the moment other than the nice ones in the libwebsockets C library, which does a good job of highlighting their utility.
The text was updated successfully, but these errors were encountered:
Is there a consistent way to do this in the current API? I would think that this example would only work with hybi since draft doesn't use ws, does it?
Is there any way to select the subprotocol at all when using draft?
I'm working on an implementation of a WebSocket subprotocol right now and need a way to see the offered subprotocols of a connection and select the subprotocol choice that is sent back to the client.
The API allows implementing multiple sub-protocols in the socket call back using a switch on socket.ws.protocol to give the different protocols different socket event call-backs. It seems it would be nicer to make the server API look more like the browser's WS API, where the protocol is specified in the connection parameters, and you get different connection objects for different sub-protocols on the same server/port.
So:
Instead of:
Or maybe there is a better way of doing this that I've missed?
Its a fairly minor and probably mostly aesthetic issue. Still a "sanctioned" way of supporting multiple protocols on the same port should really be included in the examples, since its not obvious from the API. There are few examples of using multiple WS sub-protocols on-line at the moment other than the nice ones in the libwebsockets C library, which does a good job of highlighting their utility.
The text was updated successfully, but these errors were encountered: