Closed eakteam closed 6 years ago
just call the cancel()
method
Hello, thank you for your reply. I know that , i have read how it works but where to call cancel() method outside of this thread ?
new Thread(new Runnable() {
@Override
public void run() {
try {
startTime = System.currentTimeMillis();
PortScan.onAddress(text_ip.getText().toString()).setTimeOutMillis(select_timeout).doScan(new PortScan.PortListener() {
@Override
public void onResult(final int i, boolean b) {
if (b) {
received_tcp++;
}
}
@Override
public void onFinished(ArrayList<Integer> arrayList) {
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
I have put it inside the new Thread because it throws exception : Network on Main Thread. I cannot initialize this class e.x PortScan prtsc = new PortScan(); because it says have private access.
I solve it by declaring PortScanner prt = null;
and after doing all ports scan i can call it by prt.cancel();
Thank you !
You should solve this by keeping a reference to the PortScan object that is created like so:
// Create PortScan object
PortScan portScan = PortScan.onAddress(....)...
// Then call cancel when needed
portScan.cancel()
Just want to know how to stop scanning ?