var app = require('express')(),
http = require('http'),
https = require('https'),
fs = require('fs'),
bodyParser = require('body-parser'),
request = require('request'),
sql = require('mysql'),
WebSocketLib = new require('ws');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
var optionssl = {
key: fs.readFileSync('privatekey.pem'),
cert: fs.readFileSync('certificate.pem')
},
clients = {};
http.createServer(app).listen(8001);
var SecureServer = https.createServer(optionssl, app).listen(8000);
var WebSocket = new WebSocketLib.Server({
port: 8002,
httpsServer: SecureServer,
verifyClient: true
});
console.log(WebSocket);
WebSocket.on('connection', function(ws) {
var id = Math.random();
clients[id] = ws;
console.log('Новое соединение ' + id);
ws.on('message', function(message) {
console.log('Получены данные: ' + message);
});
ws.on('close', function() {
console.log('соединение закрыто ' + id);
delete clients[id];
});
})