Commit c4e2ac131c8613519c85b6e0735080f778610317
0 parents
Exists in
master
first commit
Showing
4 changed files
with
50 additions
and
0 deletions
Show diff stats
.gitignore
config/config.ejemplo.json
index.js
... | ... | @@ -0,0 +1,28 @@ |
1 | +const webSocketServer = require('ws').Server; | |
2 | +const fs = require('fs'); | |
3 | +const config = require('./config/config.json'); | |
4 | + | |
5 | +fs.watch(__dirname, function (event, file) { | |
6 | + console.log(event); | |
7 | + console.log(file); | |
8 | +}); | |
9 | + | |
10 | +const wsServer = new webSocketServer({ | |
11 | + port: config.port | |
12 | +}); | |
13 | + | |
14 | +wsServer.on('connection', function connection(ws) { | |
15 | + console.log('open socket server') | |
16 | + | |
17 | + ws.on('message', function incoming(message) { | |
18 | + console.log('recibe ho: %s', message); | |
19 | + if (message == 'isAlive?') { | |
20 | + | |
21 | + setTimeout(function () { | |
22 | + ws.send('YES IS ALIVE'); | |
23 | + }, 10000); | |
24 | + } | |
25 | + }); | |
26 | +}); | |
27 | + | |
28 | +console.log('listen websocket port ' + config.port); |
package.json
... | ... | @@ -0,0 +1,16 @@ |
1 | +{ | |
2 | + "name": "websocketho", | |
3 | + "version": "0.0.1", | |
4 | + "description": "WebSocket Head Office", | |
5 | + "main": "index.js", | |
6 | + "dependencies": { | |
7 | + "express": "^4.16.4", | |
8 | + "ws": "^7.0.0" | |
9 | + }, | |
10 | + "devDependencies": {}, | |
11 | + "scripts": { | |
12 | + "test": "echo \"Error: no test specified\" && exit 1" | |
13 | + }, | |
14 | + "author": "Foca Software", | |
15 | + "license": "ISC" | |
16 | +} |