5

With Nearby Connections, each device has an endpointId, something similar to zkHk.

Getting the endpointId of others is trivial since it is returned by the API when scanning or connecting to other devices.

I must miss something, but I cannot find a way to get my own endpointId (apart implementing a mechanism where a connected peer echoes my id). It can be useful for some protocols where I want to follow what is sent to who.

The only thing I found is getLocalEndpointName but it returns my name, not my id. Even though it seems the C++ version of Nearby have it!

Do you have some ideas for Java/Kotlin? I specifically seek to get the endpointId, and not use alternatives like using a kind of GUID in the localendpoint name as a replacement.


Edit: Some example of usage

1) For instance, it can be interesting to implement some network mesh protocols. Several devices are interconnected making a global network, and each device add its endpointId in the incoming payload before sending it again, so others can check if they should send the payload to a device that already has it.

2) I may also want to specifically send a packet from device A to C through B acting as a relay, and add some "from: A" and "to: C" field in the payload so the network would know how to route the data and avoid some retransmission cycles. It is simpler to do that with endpointId since each device has a list of endpointId to which it is connected.

3) It can also be interesting for debug purpose. If I do some tests with a phone connected to several others (e.g. star network), it is easier to know from which phone a new piece of data is coming, all the more if I want to use name for another purpose.

Note: all of that could be done differently (e.g. use some unique identifier for the "name" of the devices and check that instead of the endpointId) but it seems a little cumbersome. All the more since endpointId guarantee a kind of unicity, whereas I must enforce it for the name. Moreover there isn't lots of information I can have on another device before exchanging data (only endpointId and name), so I feel I remove my last metadata slot if I use name as a substitute for endpointId.

Vincent Hiribarren
  • 5,254
  • 2
  • 41
  • 65

2 Answers2

0

As of today, you can't get your own endpoint id. We didn't see a reason you'd need it. Can you give a more detailed example of an algorithm where you need to know your own id?

Xlythe
  • 1,958
  • 1
  • 8
  • 12
  • 1
    Since it seems you work on the Nearby project, I guess you have the correct answer :-) I edited my question with 3 examples of potential usages, rather related to mesh network topology. Another "need" would also be to have some coherent API between the C++ and Java ones, since the C++ has a way to get it. As said, I could implement my network protocol differently using the `name` field, but it does not feel right. I will be interested to have your view about my needs. In the meanwhile I will use some GUID in the `name` field, I guess. – Vincent Hiribarren Nov 28 '17 at 07:54
0

i think you want to get your endpointId and sent its to other devices to know you again ? if yes

let's think like that : other devices will get your EndpointID and save it every time you connect to them

1)you have an Arrylist<EndPointObject> listOfUsers where EndPointObject it's an Object contain informations about Connected Endpoint Device (you create this class). we w'ill use this Arry list to save recieved Endpoint informations

2)you need to make EndPointObject class Serializable by implements Serializable,you are doing that to make it able to be converted to Byte[] and send it in payload

public class EndPointObject implements Serializable 
    {
      String endpointId ;
       .
       .
       .
    }

3)this is the Converting class add it to your project

public class SerializeHelperForPayLoad {
    public static byte[] serialize(Object object) throws IOException {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
        // transform object to stream and then to a byte array
        objectOutputStream.writeObject(object);
        objectOutputStream.flush();
        objectOutputStream.close();
        return byteArrayOutputStream.toByteArray();
    }

    public static Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException{
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
        ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
        return objectInputStream.readObject();
    }
}

4) now the strategy is every time you connect to an endpoint Device you will exchange yours EndpointObject informations,so in payloadcallback

 PayloadCallback mPayloadCallback =
            new PayloadCallback() {
                @Override
                public void onPayloadReceived(String endpointId, Payload payload) {


                    if (payload.getType() == Payload.Type.BYTES) {

                        try{
                            onDataReceived(endpointId, SerializeHelperForPayLoad.deserialize(payload.asBytes()));
                        } catch (IOException | ClassNotFoundException e) { e.getMessage(); }
                    }

                    } 
    // onData recieved void 
    void onDataReceived(String endpointId, Object object) {
                    // do something with your Object
                    EndPointObject recieved_user_info = new EndPointObject();


                   if (object.getClass() == EndPointObject.class){

                        //casting
                        recieved_user_info = (EndPointObject) object;
//now add his end pointid to his information
                        recieved_user_info.setEndpointId(endpointId);
                        listOfUsers.add(recieved_user_info);

                    }


                }

i'm very new in nearby technology ,but i hope that's helpful , by this way you can ask other end endpoint to send you your own endpointid every time

athil tech
  • 11
  • 1