Commit 1f789488fe37c6fce9673778c02029c6958caf5e
0 parents
Exists in
master
dependency
Showing
4 changed files
with
53 additions
and
0 deletions
Show diff stats
.gitignore
config/config.ejemplo.json
index.js
... | ... | @@ -0,0 +1,31 @@ |
1 | +const express = require('express'); | |
2 | +const app = express(); | |
3 | +const WebSocketClient = require('ws'); | |
4 | +const config = require('./config/config.json'); | |
5 | + | |
6 | +app.listen(config.port); | |
7 | + | |
8 | +const client = new WebSocketClient(config.urlHO); | |
9 | + | |
10 | +client.on('open', function open() { | |
11 | + console.log('conection to socket ho is open'); | |
12 | +}); | |
13 | + | |
14 | +app.get('/getSocket', function (req, res) { | |
15 | + | |
16 | + var promesa = new Promise(function (resolve, reject) { | |
17 | + | |
18 | + client.send('isAlive?'); | |
19 | + | |
20 | + client.on('message', function incoming(message) { | |
21 | + console.log('recibe bo: %s', message); | |
22 | + resolve(message); | |
23 | + }); | |
24 | + }); | |
25 | + | |
26 | + promesa.then(function (data) { | |
27 | + res.send(data); | |
28 | + }); | |
29 | +}); | |
30 | + | |
31 | +console.log('Sevice open port 6060'); |
package.json
... | ... | @@ -0,0 +1,15 @@ |
1 | +{ | |
2 | + "name": "websocketbo", | |
3 | + "version": "0.0.1", | |
4 | + "description": "WebSocket Back Office", | |
5 | + "main": "index.js", | |
6 | + "scripts": { | |
7 | + "test": "echo \"Error: no test specified\" && exit 1" | |
8 | + }, | |
9 | + "author": "Foca Software", | |
10 | + "license": "ISC", | |
11 | + "dependencies": { | |
12 | + "express": "^4.16.4", | |
13 | + "ws": "^7.0.0" | |
14 | + } | |
15 | +} |