Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PortScan() blocked UI thread and caused Progress Dialog is stopped and hang #58

Closed
jerrychong25 opened this issue Sep 9, 2019 · 6 comments
Labels

Comments

@jerrychong25
Copy link

Hi all,

I have implemented PortScan() function successfully.

However, it will block my Progress Dialog when running PortScan() function, whereby my Progress Dialog is called before PortScan() function.

The Progress Dialog is stopped and hang half way until the PortScan() is executed completely.

Is there any way to prevent blocking of my Progress Dialog when running PortScan() function?

Thanks.

My Source Code:

// Find Port Number Asynchronously
PortScan.onAddress("192.168.1.11").setTimeOutMillis(500).setPortsAll().setMethodTCP().doScan(object:

    PortScan.PortListener {
        override fun onResult(portNum:Int, open:Boolean) {
            if (open) {
                // Found new open port
            }
        }

        override fun onFinished(openPorts:ArrayList<Int>) {
            // Finished Scanning
            if(openPorts.isEmpty()) {

            }
            else {

            }
        }
    }
)
@jerrychong25 jerrychong25 changed the title PortScan block UI thread PortScan() blocked UI thread and caused Progress Dialog is stopped and hang Sep 9, 2019
@jerrychong25
Copy link
Author

Similar issue:
#51

@jerrychong25
Copy link
Author

@semenovalexander

Any updates on this?

Thanks.

@stealthcopter
Copy link
Owner

@jerrychong25 @semenovalexander Hi Both,

I've used the following code on android 6.0 and 9.0 and do not get UI blocking. I'll run some tests on < 6.0 and see what I get. Do you still get the blocking if you set the thread count to a low number? might be worth testing with 1.

        // Find Port Number Asynchronously
        PortScan.onAddress("192.168.0.50").setTimeOutMillis(500).setPortsAll().setMethodTCP().doScan(new PortScan.PortListener() {
            @Override
            public void onResult(int portNo, boolean open) {
                Log.e("TEST","Result: "+portNo+" "+open);
            }

            @Override
            public void onFinished(ArrayList<Integer> openPorts) {
                Log.e("TEST","Result: "+openPorts.size());
            }
        });

@jerrychong25
Copy link
Author

@jerrychong25 @semenovalexander Hi Both,

I've used the following code on android 6.0 and 9.0 and do not get UI blocking. I'll run some tests on < 6.0 and see what I get. Do you still get the blocking if you set the thread count to a low number? might be worth testing with 1.

        // Find Port Number Asynchronously
        PortScan.onAddress("192.168.0.50").setTimeOutMillis(500).setPortsAll().setMethodTCP().doScan(new PortScan.PortListener() {
            @Override
            public void onResult(int portNo, boolean open) {
                Log.e("TEST","Result: "+portNo+" "+open);
            }

            @Override
            public void onFinished(ArrayList<Integer> openPorts) {
                Log.e("TEST","Result: "+openPorts.size());
            }
        });

No issue on low number.

But in my application use case, I need to set setPortsAll() function so is there any other workaround for this?

@rmirabelle
Copy link

Related to this issue...

In my case, my Activity calls a method called scan_subnet(), which does a subnet scan. When calling scan_subnet() from onCreate(), the Activity hasn't finished rendering its UI yet, and so freezes/locks up/blocks until the scan is complete.

I was able to fix this by hooking into the onWindowFocusChanged event instead of onCreate or onResume or even onAttachedToWindow, each of which blocks the UI before the Activity is fully rendered.

//kotlin
override fun onWindowFocusChanged(hasFocus: Boolean) {
    super.onWindowFocusChanged(hasFocus)
    if(hasFocus) {
        scan_subnet()
    }
}

This feels a bit hacky, but works for my needs.

I would like this library to handle the UI blocking issues more elegantly, without having to manually deal with threading concerns.

@jerrychong25
Copy link
Author

No longer using AndroidNetworkTools nowadays. Will close this issue.

Thanks all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants