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

SendMessageTo - can't use MAC address and we don't have ip addresses #77

Open
seba9999 opened this issue Mar 18, 2023 · 7 comments
Open

Comments

@seba9999
Copy link
Contributor

The list of peer only provide peers info with some MAC addresses ... But for now the sendMessage uses InetSocketAddress which can't use MAC addresses.

I'll maybe try to pass the ip from the client to the server at first message ( in order to be able to transfert message from group owner to clients )

Or we need some refactoring in the sendMessage function to add extra fields to store ip list of devices / peer in the group ...

@kirillzyusko
Copy link
Owner

I'll maybe try to pass the ip from the client to the server at first message ( in order to be able to transfert message from group owner to clients )

Hi @seba9999
Let me know, whether it works for you or not 👀

@viniciuscb
Copy link
Contributor

Hi @seba9999 . I tried to find how can one know the ip addresses of other peers. What I've found is that people is sending a first message from clients (peers) to group owner to know the IP. After that, the communication continues normally.

I think that the README should be updated explaining this usage.

@seba9999
Copy link
Contributor Author

Yeah I've found thoses threads ... But I can't believe there's nothing newer than 10 years old !

Is it still the best ( right ) way of doing such "broadcast" ?

It would be better to implement it java side no ? I'm wondering

@viniciuscb
Copy link
Contributor

viniciuscb commented Mar 20, 2023

Hi @seba9999 . The problem is that the information that we receive in react native is exactly the information that android gives us.

I've sent a PR now ( #80 ) that changes the receiveMessage method, and we also receive in react native the ip of the sender. In my application I am using like this:

  if (connectionInfo.groupFormed) {
    if (!connectionInfo.isGroupOwner) {
      sendMessage('it can be anything here');
    } else {
      receiveMessage({meta: true}).then(({fromAddress, message}) => {
        // now you have the IP address of the peer in fromAddress. You can store it
        // somewhere to use in the future: sendMessageTo(message, address)
      });
    }
  }

It seems to me that this is the best solution, as if the client tries to find its own IP address through other method, it will need to filter, because the device most surely have several: ipv4 and ipv6 (localhost ip, current network ip and the wifip2p ip). When I receive the message, in java, I get the information of the source ip in the client socket through which the message is coming. This is the IP of the sender in the wifip2p network.

@viniciuscb
Copy link
Contributor

I've not tried to send a message to the broadcast address, though.

@viniciuscb
Copy link
Contributor

viniciuscb commented Mar 20, 2023

as receiveMessage receives just one message, I'm implementing it the following way:

  const onReceiveMessage = () => {
    receiveMessage({meta: true})
      .then({ fromAddress, message } => {
        let receiveNextMessage = true;

        // Conditions: depending on the message received or other logic, will 
        // close the connection and set receiveNextMessage to false. 
        //     
        // Can call stopReceivingMessage() to close opened socket. I am calling 
        // on screen exit (useEffect return) just in case. This ensures the promise.resolve()
        // callback won't be called in another context, i.e. another screen....

        if (receiveNextMessage) {
          onReceiveMessage();
        }
      })
      .catch(err => {
        console.log(user.name + ':   Error while message receiving', err);
        onReceiveMessage();
      });
  };

@Suyashbajpai27
Copy link

I have same issue that i am not able to send message because it is capturing the MAC address not IP address.

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

No branches or pull requests

4 participants