-
Notifications
You must be signed in to change notification settings - Fork 155
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
Create server follow another http or https server #15
Comments
I'm working on a project that is using nodejs-websocket This ticket has been closed without comment
Maybe there is another approach available, like:
Thanks, Regards |
Looks like similar requirement was raised in #3 From the answer on that ticket, one of the limitation would be that this module is directly bound to the tls.Server or net.Server socket level without the http layer So...
Which means that when the var http = require("http")
var ws = require("nodejs-websocket")
var wsServer;
var httpServer = http.createServer();
httpServer.on('upgrade', function (req, socket, head) {
wsServer = ws.createServer({ socket: socket, upgradeHead: head }, function (conn) {
conn.on("text", function (str) {
conn.sendText(str.toUpperCase()+"!!!")
})
conn.on("close", function (code, reason) {
console.log("Connection closed")
})
});
});
httpServer.listen(8001); It may worth a try
|
Didn't tested but the implementation could look like var socket = options.socket;
if (socket && (socket instanceof tls.TLSSocket || socket instanceof net.Socket)) {
this.socket = options.socket
} else if (secure) {
this.socket = tls.createServer(options, onConnection)
} else {
this.socket = net.createServer(options, onConnection)
} Plus some code to handle the upgrade handshake |
looks good. |
I've implemented in #66, you can try to use it and check if everything works well |
RT, like https://www.npmjs.com/package/ws support new WebSocketServer({server: httpServer});
The text was updated successfully, but these errors were encountered: