Skip to content
This repository has been archived by the owner on Dec 29, 2019. It is now read-only.

Busy error while attempting to start network service #15

Open
nitrocalcite opened this issue Jul 9, 2016 · 10 comments
Open

Busy error while attempting to start network service #15

nitrocalcite opened this issue Jul 9, 2016 · 10 comments

Comments

@nitrocalcite
Copy link

nitrocalcite commented Jul 9, 2016

When I call network.startNetworkService(), it works once, but then consistently logs an error "Failed to create group. Reason :2". This error is created when, internally, the manager.createGroup() method is called. Error code 2 corresponds to BUSY.

This issue is resolved if I manually turn off wifi and turn it back on again. If I do so programmatically, like so:

WifiManager wifiManager = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(false);
wifiManager.setWifiEnabled(true);

the problem persists.

I've also tried using network.stopNetworkService() in the onStop() or onDestroy() methods of my activity but to no avail.

Does anyone know how to resolve this error? StackOverflow says that it can be caused by a call to manager.removeGroup() when you aren't connected to a group, but that is not applicable. In addition, Base.java uses much the same code as I do, yet when I run it in an example project, this error never occurs.

@neatorobito
Copy link
Owner

Are you calling stopNetworkServicebefore testing again? Or do you simply restart the app?

And the framework can actually call manager.removeGroup() in some instances (obviously if you have called the stopNetworkServicemethod) in which the device isn't actually connected to a group.

@phyron
Copy link

phyron commented Sep 19, 2016

Hi, I have the same issue. And I need to turn off wifi manually and turn it back.
I never call the stopNetworkServicebefore method.
The issue, I think that appears when the app is crashed. After restart, the issue appears. The first time the app is open, work perfectly.

Any solution?

EDIT

I found this "solution":
POST
But I don't know how to close group using salut.

@neatorobito
Copy link
Owner

neatorobito commented Sep 19, 2016

That would be this function.

https://github.com/markrjr/Salut/blob/master/src/main/java/com/peak/salut/Salut.java#L435

EDIT
It's been a while since I have worked on/with the library, so I try to respond to these issues as best I can. I apologize for any inconvenience.

@neatorobito
Copy link
Owner

What devices are you testing on?

@phyron
Copy link

phyron commented Sep 22, 2016

Ok, the issue appears when I close the app. But not if I close normally (pushing the back button of device), only appear if I push the Overview button (right button), and drag app for close. I see in the logcat that he can't close a group. The problem is with host. And when restart app, show the other erroir message.
I add thi scode, but nothing:

 public void onDestroy() {
        super.onDestroy();
        host.stopHost();
    }
    public void onStop() {
        super.onStop();
        host.stopHost();
    }
 protected void stopHost(){

        network.stopNetworkService(false);

    }

@neatorobito
Copy link
Owner

neatorobito commented Sep 22, 2016

Try replacing network.stopNetworkService(false) with manual calls tonetwork.disconnectFromDevice() and then network.forceDisconnect() in that order in your stopHost method.

 protected void stopHost() {
    network.disconnectFromDevice();
    network.forceDisconnect();
}

@phyron
Copy link

phyron commented Sep 30, 2016

I can't access to these methods because are protected.
Other question: How I can get the client device in host when client is disconnected?

@neatorobito
Copy link
Owner

neatorobito commented Oct 19, 2016

It's been a while since I've written Java but doesn't protected mean that derived objects can access the methods? So you should have access to those methods. If that's not the case, then you'll have to manually change the methods and add the repo as a module in your project.

As for your other question, I'm not quite sure what you're asking.

@pasniak
Copy link

pasniak commented May 30, 2017

I am trying to WiFi data exchange capability to an app. And I might have a similar error.

Regarding the fix: in my case I split the class which implements SalutDataCallback (it is a Service) and the activity (MainActivity) so I access the mNetwork object in the activity. In which cannot call protected methods...
https://i.imgur.com/ERbTRul.png

@Aawesh
Copy link

Aawesh commented Jun 19, 2017

Any updates on this? I am getting the same issue.

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

No branches or pull requests

5 participants