From 30828c35a274d47d4a7713559cfe49c1cbe519ee Mon Sep 17 00:00:00 2001 From: zeus Date: Wed, 28 Oct 2020 20:47:43 +0200 Subject: [PATCH] add network host --- src/IoT/llo/bclient.js | 14 +++++--------- src/IoT/llo/iotclient.js | 35 ++++++++--------------------------- src/IoT/llo/iotserver.js | 4 ++-- start-iotclient-n.sh | 3 +++ start-iotclient.sh | 2 +- stop-all.sh | 6 ++++++ stop-iotclient-n.sh | 4 ++++ 7 files changed, 29 insertions(+), 39 deletions(-) create mode 100755 start-iotclient-n.sh create mode 100755 stop-all.sh create mode 100755 stop-iotclient-n.sh diff --git a/src/IoT/llo/bclient.js b/src/IoT/llo/bclient.js index f9fbd6b..9c55405 100644 --- a/src/IoT/llo/bclient.js +++ b/src/IoT/llo/bclient.js @@ -16,33 +16,29 @@ socketoptions = { var io2 = require('socket.io-client'); var socket = io2.connect('http://localhost:8084', socketoptions); + socket.on('connection', s => { console.error('socket2 connection'); var id = s.id var roomiot = 'iot' - socket.emit('iot', roomiot); - - socket.emit('subscribe', roomiot); + s.emit('subscribe', roomiot); - socket.emit('pingServerEmit', roomiot); + s.emit('log', 'Hi from client-n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1'); s.on('message', function (data) { console.log('from room1 '+data); }); - s.on('iot', function (data) { - console.log('from room1 '+data); - }); }); var roomiot = 'iot' - socket.emit('iot', roomiot); + socket.emit('subscribe', roomiot); socket.on('message', function (data) { console.log('from room '+data); }); - + socket.emit('log', 'Hi from client-n'); diff --git a/src/IoT/llo/iotclient.js b/src/IoT/llo/iotclient.js index 5faffd9..71b6653 100644 --- a/src/IoT/llo/iotclient.js +++ b/src/IoT/llo/iotclient.js @@ -101,43 +101,24 @@ socket.on('connection', s => { console.error('socket2 connection'); global.id = s.id s.emit('log', 'client'); -/* - var roomiot = 'iot' - s.emit('subscribe', roomiot); - - s.on('customEmit', obj => { - console.error('socket2fromServer'); - var data = obj+' test2 customeEdit '+id - console.error('from server2client ' + data); - }); s.on('message', function (data) { - console.log('from room '+data); - //io.emit("customEmit", data) - }); - //s.to(room).emit('message', 'hi from server'); - s.on('iot', function (data) { - console.log('from room '+data); - //io.emit("customEmit", data) - }); - - socket.on('iot', function (data) { - console.log('from room '+data); - //io.emit("customEmit", data) - }); - - socket.on('message', function (data) { - console.log('from room '+data); + //console.log('from room ' + data); + console.log("from room iot "+JSON.stringify(data)) //io.emit("customEmit", data) }); -*/ + s.in('iot').emit('log', data); + s.in('iot').emit('message', data); }); var roomiot = 'iot' socket.emit('subscribe', roomiot); - socket.emit('log', 'client1'); + socket.emit('log', 'Hi client1 here'); + var data = 'Hi client A!' + + socket.on('message', function (data) { //console.log('from room ' + data); diff --git a/src/IoT/llo/iotserver.js b/src/IoT/llo/iotserver.js index 432fbda..38902a2 100644 --- a/src/IoT/llo/iotserver.js +++ b/src/IoT/llo/iotserver.js @@ -47,7 +47,7 @@ cors(corsOptions), (req, res, next) => { var RES = new Object(); RES.code = req.query["code"] - console.error('socket get from client' + RES.code); + console.error('socket GET from client ' + RES.code); RES.error = false RES.error_msg = "ok" @@ -63,7 +63,7 @@ app.post('/run', [ //check('llo').isBase64() ], cors(corsOptions), (req, res, next) => { - console.error('socket post from client'); + console.error('socket POST from client'); io.emit("customEmit", 'data') var RES = new Object(); diff --git a/start-iotclient-n.sh b/start-iotclient-n.sh new file mode 100755 index 0000000..83fb029 --- /dev/null +++ b/start-iotclient-n.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker run --rm -it --name iotclient-n --network="host" -v $PWD/src:/home/node/iot-swarm-example/src hub.swarmlab.io:5443/iot-swarm-example:latest node /home/node/iot-swarm-example/src/IoT/llo/bclient.js diff --git a/start-iotclient.sh b/start-iotclient.sh index c5b5bfe..c7195a2 100755 --- a/start-iotclient.sh +++ b/start-iotclient.sh @@ -1,3 +1,3 @@ #!/bin/bash -docker run --rm -it --name iotclient -p 3081:3081 -v $PWD/src:/home/node/iot-swarm-example/src hub.swarmlab.io:5443/iot-swarm-example:latest node /home/node/iot-swarm-example/src/IoT/llo/iotclient.js +docker run --rm -it --name iotclient -p 3081:3081 --network="host" -v $PWD/src:/home/node/iot-swarm-example/src hub.swarmlab.io:5443/iot-swarm-example:latest node /home/node/iot-swarm-example/src/IoT/llo/iotclient.js diff --git a/stop-all.sh b/stop-all.sh new file mode 100755 index 0000000..46dad2d --- /dev/null +++ b/stop-all.sh @@ -0,0 +1,6 @@ +#!/bin/bash +./stop-iotclient-n.sh +./stop-iotclient.sh +./stop-iotserver.sh +./stop-iotwebclient.sh + diff --git a/stop-iotclient-n.sh b/stop-iotclient-n.sh new file mode 100755 index 0000000..119ea08 --- /dev/null +++ b/stop-iotclient-n.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +docker stop iotclient-n +docker rm iotclient-n