Browse Source

add network host

master
zeus 4 years ago
parent
commit
30828c35a2
  1. 14
      src/IoT/llo/bclient.js
  2. 35
      src/IoT/llo/iotclient.js
  3. 4
      src/IoT/llo/iotserver.js
  4. 3
      start-iotclient-n.sh
  5. 2
      start-iotclient.sh
  6. 6
      stop-all.sh
  7. 4
      stop-iotclient-n.sh

14
src/IoT/llo/bclient.js

@ -16,33 +16,29 @@ socketoptions = {
var io2 = require('socket.io-client'); var io2 = require('socket.io-client');
var socket = io2.connect('http://localhost:8084', socketoptions); var socket = io2.connect('http://localhost:8084', socketoptions);
socket.on('connection', s => { socket.on('connection', s => {
console.error('socket2 connection'); console.error('socket2 connection');
var id = s.id var id = s.id
var roomiot = 'iot' var roomiot = 'iot'
socket.emit('iot', roomiot); s.emit('subscribe', roomiot);
socket.emit('subscribe', roomiot);
socket.emit('pingServerEmit', roomiot); s.emit('log', 'Hi from client-n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1');
s.on('message', function (data) { s.on('message', function (data) {
console.log('from room1 '+data); console.log('from room1 '+data);
}); });
s.on('iot', function (data) {
console.log('from room1 '+data);
});
}); });
var roomiot = 'iot' var roomiot = 'iot'
socket.emit('iot', roomiot); socket.emit('subscribe', roomiot);
socket.on('message', function (data) { socket.on('message', function (data) {
console.log('from room '+data); console.log('from room '+data);
}); });
socket.emit('log', 'Hi from client-n');

35
src/IoT/llo/iotclient.js

@ -101,43 +101,24 @@ socket.on('connection', s => {
console.error('socket2 connection'); console.error('socket2 connection');
global.id = s.id global.id = s.id
s.emit('log', 'client'); 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) { s.on('message', function (data) {
console.log('from room '+data); //console.log('from room ' + data);
//io.emit("customEmit", data) console.log("from room iot "+JSON.stringify(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);
//io.emit("customEmit", data) //io.emit("customEmit", data)
}); });
*/ s.in('iot').emit('log', data);
s.in('iot').emit('message', data);
}); });
var roomiot = 'iot' var roomiot = 'iot'
socket.emit('subscribe', roomiot); socket.emit('subscribe', roomiot);
socket.emit('log', 'client1'); socket.emit('log', 'Hi client1 here');
var data = 'Hi client A!'
socket.on('message', function (data) { socket.on('message', function (data) {
//console.log('from room ' + data); //console.log('from room ' + data);

4
src/IoT/llo/iotserver.js

@ -47,7 +47,7 @@ cors(corsOptions), (req, res, next) => {
var RES = new Object(); var RES = new Object();
RES.code = req.query["code"] 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 = false
RES.error_msg = "ok" RES.error_msg = "ok"
@ -63,7 +63,7 @@ app.post('/run', [
//check('llo').isBase64() //check('llo').isBase64()
], ],
cors(corsOptions), (req, res, next) => { cors(corsOptions), (req, res, next) => {
console.error('socket post from client'); console.error('socket POST from client');
io.emit("customEmit", 'data') io.emit("customEmit", 'data')
var RES = new Object(); var RES = new Object();

3
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

2
start-iotclient.sh

@ -1,3 +1,3 @@
#!/bin/bash #!/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

6
stop-all.sh

@ -0,0 +1,6 @@
#!/bin/bash
./stop-iotclient-n.sh
./stop-iotclient.sh
./stop-iotserver.sh
./stop-iotwebclient.sh

4
stop-iotclient-n.sh

@ -0,0 +1,4 @@
#!/bin/bash
docker stop iotclient-n
docker rm iotclient-n
Loading…
Cancel
Save