neatorobito / Salut

A nice library for working with WiFi P2P service discovery on Android.
MIT License
297 stars 89 forks source link

WiFi connection required for discovery? #19

Open danielrearden opened 7 years ago

danielrearden commented 7 years ago

I created a simple app using the code in the readme to try out the library. It works great and I'm able to send messages between my two devices. However, I noticed the service discovery only works when the host device is connected to a WiFi network.

It doesn't matter if the client device is connected to the same network, a different one, or not at all. However, when the host device isn't connected to some network, it's not discoverable by the client device (even though WiFi is still turned on!). In either case, I receive a "successfully created service" message but it's like the host is not advertising the service unless it's connected to an existing WiFi network.

I have not used WiFi Direct outside of this library, so I'm not sure what the expected behavior is but I thought the API is supposed to allow devices to connect even without an access point.

Any advice on this would be greatly appreciated!

relevante commented 7 years ago

I ended up not using Salut, but I've just encountered this in my own WifiP2p implementation. It seems to only affect some devices. The Nexus 4 works without being connected to WiFi, but the Galaxy S5 I'm using seems to require a WiFi connection to properly establish a group. The interesting thing is that the other device will still connect to it, but it can never get a groupOwnerAddress unless the S5 is on a WiFi network.

neatorobito commented 7 years ago

Interesting. Try connecting without using groups.

On Jan 18, 2017 7:00 AM, "relevante" notifications@github.com wrote:

I ended up not using Salut, but I've just encountered this in my own WifiP2p implementation. It seems to only affect some devices. The Nexus 4 works without being connected to WiFi, but the Galaxy S5 I'm using seems to require a WiFi connection to properly establish a group. The interesting thing is that the other device will still connect to it, but it can never get a groupOwnerAddress unless the S5 is on a WiFi network.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/markrjr/Salut/issues/19#issuecomment-273469127, or mute the thread https://github.com/notifications/unsubscribe-auth/AC37HT4009ibzTHrjAjiY3qriGli-xvgks5rTgzhgaJpZM4K-pYh .

relevante commented 7 years ago

Thanks! That seems to fix it.

neatorobito commented 7 years ago

How did you connect without using groups?

Thanks,

Mark Raymond Jr.

On Jan 18, 2017, at 9:55 AM, relevante notifications@github.com wrote:

Thanks! That seems to fix it.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/markrjr/Salut/issues/19#issuecomment-273514469, or mute the thread https://github.com/notifications/unsubscribe-auth/AC37HTVxrzumKW4vYrpdG4iEjlITsrHFks5rTjXYgaJpZM4K-pYh.

relevante commented 7 years ago

I'm just connecting to a device that I get in the WIFI_P2P_PEERS_CHANGED_ACTION intent after starting peer discovery. It seems that a group is created automatically though, as I'm getting its info and removing it to disconnect. But somehow me not explicitly creating it in advance appears to have fixed the initial problem. I'm not 100% sure as there's a enough flakiness in the overall system that it's hard to be completely certain, but it seems to be working well now, at least on these phones.

neatorobito commented 7 years ago

Huh, interesting. WiFi Direct in Android is quite flaky. I will probably implement the change in Salut as well. Thanks for the info!

relevante commented 7 years ago

Sure thing, I'll let you know if anything becomes clearer as I proceed.

ManasviniGanesh commented 7 years ago

The log says I successfully received a message, but the message is not being parsed. Used every code the way you described. yet no remedy. onDataReceived(Object o) {} is never getting executed !

abselt commented 7 years ago

@ManasviniGanesh for me, sometimes it works sometime no... have you found a solution please?