Reputation: 631
I need to implement the communication among all the devices connected to same WiFi AP. I am using the Google Nearby Connections APIs. I am able to connect to multiple device and communicate. But due to some problem connection getting lost. I have checked the Google documentation, It suggest that "When a device is connected to the host, it may send messages to other client devices."
https://developers.google.com/nearby/connections/android/manage-connections
My doubt is what it mean "it may send messages to other client devices".
If multiple client devices are connected to a Host device, then how a client device can send a message to other client devices?
Upvotes: 1
Views: 1019
Reputation: 56
Connections when using Nearby Connections API are lost when
so I think you should log some of these cases.
"it may send messages to other client devices"
developer page mean that a connection status (Accepted, Rejected etc) can be send when the host responds to the connection request.
If multiple client devices are connected to a Host device, then how a client device can send a message to other client devices?
And, if multiple devices are connected you can send your message (or I should rather say Data) to the host which will send the same data to all the clients connected to it (That's how most of the Host-Client system works).
I hope it helped
Upvotes: 1
Reputation: 1020
I never tried this, but it seems you can get the clients endpointId with Nearby.Connections.getLocalEndpointId()
on the client devices. Not sure how this helps sending messages to other clients, because the host knows the Client-EndpointIds anyway...
However, as a proof of concept you could do something like this:
In the Host:
String payload = client2EndpointId;
Nearby.Connections.sendReliableMessage(mGoogleApiClient, client1EndpointId, payload);
In the Client1:
@Override
public void onMessageReceived(String endpointId, byte[] payload, boolean isReliable) {
String client2EndpointId = (String) payload;
Nearby.Connections.sendReliableMessage(mGoogleApiClient, client2EndpointId, messageFromClient1ToClient2);
}
And in Client2:
@Override
public void onMessageReceived(String endpointId, byte[] payload, boolean isReliable) {
String messageFromClient1 = (String) payload;
}
The Host sends client2's EndpointId as a message to client1. Client1 then uses this endpointId to send a message to client2.
Upvotes: 1