How to use the same port to start the web server (express) and web socket server in the same port in NodeJS ?
//app.js
var WebSocketServer = require('ws').Server
, http = require('http')
, express = require('express')
, app = express();
app.use(express.static(__dirname + '/'));
var server = http.createServer(app);
var wss = new WebSocketServer({server:server});
wss.on('connection', function (ws) {
ws.on('close', function () {
console.log('close:');
});
ws.on('message', function (message) {
console.log('message:', message);
});
});
server.listen(3000);
No comments:
Post a Comment