Hi
Please i'm looking for a sample of connecting to a Mikrotik router with B4J though a api.
Found this java code.
Please if somebody just can show me in the right direction to do this... THX
Please i'm looking for a sample of connecting to a Mikrotik router with B4J though a api.
Found this java code.
Please if somebody just can show me in the right direction to do this... THX
Java:
ApiConnection ret = new ApiConnection("192.168.88.1", 8728);
if (!ret.isConnected()) {
ret.start();
try {
ret.join();
if (ret.isConnected()) {
ret.login("admin", new char[0]);
}
} catch (InterruptedException ex) {
Logger.getLogger(T3apiView.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
aConn.sendCommand("/ip/address/print");
DataReceiver dataRec = new DataReceiver(aConn, this);
dataRec.start();
B4X:
import libAPI.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author janisk
*/
public class DataReceiver extends Thread {
private ApiConnection aConn = null;
T3apiView t3A = null;
public DataReceiver(ApiConnection aConn, T3apiView t3A) {
this.aConn = aConn;
this.t3A = t3A;
}
@Override
public void run() {
String s = "";
while (true) {
try {
s = aConn.getData();
if (s != null) {
t3A.outputHere(s);
if (s.contains("!done")) {
}
}
} catch (InterruptedException ex) {
Logger.getLogger(DataReceiver.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}