Commit 1f789488fe37c6fce9673778c02029c6958caf5e

Authored by Eric Fernandez
0 parents
Exists in master

dependency

File was created 1 /config/config.json
2 /node_modules
3 /package-lock.json
4
config/config.ejemplo.json
File was created 1 {
2 "urlHO": "ws://localhost:5050",
3 "port": 6060
4 }
File was created 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');
32
File was created 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 }
16