Enr Bel
Enr Bel

Reputation: 23

Create a tcp connection using mac address on Android

On an Android device, I want to create a tcp communication on a local network with a device that I know only the mac address (no the ip). There is a way to start the communication with only the mac address or, alternatively, to find directly the ip associated without scan all network looking for the device? Thank you very much

Upvotes: 2

Views: 1823

Answers (1)

eleven
eleven

Reputation: 6857

To deliver ip address of your server to a client you can send broadcast UDP packet from server. The flow could look like this:

  1. Server opens TCP port and waits for TCP clients.
  2. Server sends broadcast UDP packet with specific data ( something which says that this packet is from your server )
  3. If there is a client in the same network it receives the packet. The client reads data, checks that the packet is from your server. This packet also has ip address of your server.
  4. That is all: now client knows ip address and port, it connects through TCP to your server.
  5. Server accepts new client. Connection is done.

Here is sample of how UDP packet could be sent and received: https://stackoverflow.com/a/25520279/798165

Upvotes: 2

Related Questions