Comments (17)
Are you sure that the first one was disconnected?
Also, this seems like an issue with the logic used in your socket.io, where you are using the same event to send message for two distinct connection, you could try using rooms. But the way it is now, make sure you have disconnected from the previous router by looking at the logs of the router itself, maybe this line is never running:
if(status == true) {
...
} else {
if (api) {
const closing = api.rosApi.closing; // you don't have to check it yourself, the api already does this
if (!closing) api.close(); // <- this line must run
}
}
from routeros-client.
Unfortunately, I reviewed my code there is not mistake. I am sure that routeros does not close once I use routeros.close() even I used console.log(routeros.rosApi.host) after routeros.close(), it shows me server host name. I used also routeros.disconnect(), it's still remain give me server information.
from routeros-client.
I`ll try to get a lab running with 2 routeros instances, but I fail to see where the lib might be failing to disconnect.
Have you tried this?
if(status == true) {
...
} else {
if (api) {
api.close();
}
}
from routeros-client.
Yes, api.close() and api.disconnect() does not work, server still remain shows me information after I use these commands.
from routeros-client.
I've setup a lab with 2 routeros using chr for testing, adapted your code for the setup and it worked just fine.
Here is a gif of it:
https://drive.google.com/open?id=1nIKIQqY65NxNkn1ZVH1ccJqUkxMNxZyf
Here is the code I used:
const { RouterOSClient } = require("routeros-client");
const serverConnection = (data) => {
return new RouterOSClient({
host: data.host,
user: data.user,
password: data.password,
keepalive: true,
timeout: 50
});
};
let api;
const totalClients = (serverData, status) => {
if (status == true) {
api = serverConnection(serverData);
api.connect().then(client => {
console.log(`connected into ${serverData.host}`);
client.menu("/ppp secret")
.query({ interval: 2 })
.stream('print', (err, data) => {
if (err) {
console.error(err);
}
if (data.length > 0) {
console.info(data.length);
}
});
});
} else {
if (api) {
api.close().then(() => {
console.log("disconnected");
});
}
}
}
const server1 = {
host: '192.168.0.110',
user: 'admin',
password: 'admin'
};
const server2 = {
host: '192.168.0.111',
user: 'admin',
password: 'admin'
};
totalClients(server1, true);
setTimeout(() => {
totalClients(server1, false);
totalClients(server2, true);
setTimeout(() => {
totalClients(server2, false);
}, 10 * 1000);
}, 10 * 1000);
from routeros-client.
I've tested with just node-routeros
and debugged some information, can confirm that, even if the api is disconnecting, the stream won't stop sending data.
from routeros-client.
I've issued an update to node-routeros
that might fix it, try updating to see if that solves this issue.
from routeros-client.
Should I use node-routeros instead of routeros-client?
from routeros-client.
No, just do an npm update
and check if the underlying node-routeros gets updated to 1.6.7.
node-routeros is a sub-package of routeros-client.
from routeros-client.
Actually, on my app I am using just routeros-client package. I update these package, but still same issue. This is my whole code:
`const RouterOSClient = require('routeros-client').RouterOSClient
require('dotenv').config()
let api
module.exports = (io) => {
io.on('connection', (socket) => {
socket.on('StartGetInformation', (serverData, status) => {
if(status == false) {
if(api) {
api.close()
}
} else {
api = new RouterOSClient({
host: serverData.host,
user: serverData.user,
password: serverData.password,
keepalive: true,
timeout: 100
})
api.connect().then(client => {
client.menu("/tool torch")
.where({interface: "WAN-1"})
.stream((err, packet) => {
if(packet.length > 0) {
const rxData = packet[0].rx / (1000 * 1000)
const rxDataRounded = Math.round(rxData)
const txData = packet[0].tx / (1000 * 1000)
const txDataRounded = Math.round(txData)
const data = {rx: rxDataRounded, tx: txDataRounded}
io.emit('SendSpeedData', data)
}
})
client.menu("/ppp active")
.query({ interval: 5 })
.stream('print', (err, data) => {
if(data.length > 0) {
io.emit('Clients-Active', data.length)
}
})
client.menu("/ppp secret")
.query({ interval: 5 })
.stream('print', (err, data) => {if(data.length > 0) io.emit('Clients-Length', data.length)})
}).catch(err => {
console.log(err)
})
}
})
})
}`
from routeros-client.
I see, I may need to force an update through package.json then, routeros-client
uses node-routeros
under the hood.
from routeros-client.
I've updated routeros-client
to v1.0.2 which should force node-routeros
to update too. Could you try it again with those versions?
Edit: routeros-client
should now be at version 1.1.0
.
from routeros-client.
I do not know sometimes work perfectly, and sometimes shows me same issue.
Is it normal if I use api.close() to get inflrmation about server like host.
I use command: console.log(api.rosApi.host) after api.close(), these command shows me host name.
from routeros-client.
I do not know sometimes work perfectly, and sometimes shows me same issue.
Is it normal if I use api.close() to get inflrmation about server like host.
I use command: console.log(api.rosApi.host) after api.close(), these command shows me host name.
It is, the routeros information will remain with the "api" object until you don't use it anymore and the garbage collector removes it from memory. This lib will reuse this information to do re-logins and etc.
from routeros-client.
Do you have any idea to remove these information and clear "api" object completely from memory.
from routeros-client.
To be honest, you shouldn't be using the "rosApi" property since it is private.
I really don't understand what is still the issue you are having, after version 1.1.0 of routeros-client
and version 1.6.6 of node-routeros
, in my lab with a sample of your code, it worked just fine.
Can you provide any logging information?
from routeros-client.
Closing this issue since there was no response from the OP.
from routeros-client.
Related Issues (17)
- improve remove, update and etc to query for the id of the entry HOT 2
- speed-test stream HOT 3
- getting an exception while deleting a record
- Connect to multiple devices at the same time
- Where Filter Not Working With Update, Delete, Remove.
- I cant add user to radius server via /tool/user-manage/add anyone can help me HOT 1
- Cannot connect through VPN HOT 11
- problem on torch pppoe interface
- Error: Username or password is invalid HOT 2
- Error with TypeScript 2.9.2 HOT 4
- Stream does not work HOT 2
- events.js:167 throw er; // Unhandled 'error' event HOT 3
- TypeError: RouterOSClient is not a constructor HOT 2
- Request: an add time function for some timer parameters HOT 1
- RosException HOT 5
- cant get /interface/wireless/monitor Information HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from routeros-client.