wss testing

This commit is contained in:
2019-04-26 01:44:01 +10:00
parent f9b5512073
commit 449db92e01
3 changed files with 49 additions and 6 deletions

32
plugins/wss.js Normal file
View File

@@ -0,0 +1,32 @@
const fs = require('fs');
const https = require('https');
const WebSocket = require('ws');
const fs = require("fs")
module.exports = {
name: "Websockets Server (8080)",
init: (dclient) => {
client = dclient
const server = https.createServer({
cert: fs.readFileSync('./cert.pem'),
key: fs.readFileSync('./privkey.pem')
});
const wss = new WebSocket.Server({ server });
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
console.log('received: %s', message);
ws.send(`something ${message}`);
});
ws.send('something');
});
server.listen(8080);
}
}