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
Asked
Active
Viewed 1,547 times
1 Answers
2
To deliver ip address of your server to a client you can send broadcast UDP packet from server. The flow could look like this:
Server
opens TCP port and waits for TCPclients
.Server
sends broadcast UDP packet with specific data ( something which says that this packet is from yourserver
)- If there is a
client
in the same network it receives the packet. Theclient
reads data, checks that the packet is from yourserver
. This packet also has ip address of yourserver
. - That is all: now
client
knows ip address and port, it connects through TCP to yourserver
. Server
accepts newclient
. Connection is done.
Here is sample of how UDP packet could be sent and received: https://stackoverflow.com/a/25520279/798165

eleven
- 6,779
- 2
- 32
- 52
-
1Great solution! I implemented and it works perfectly. It also help me to add more helpful utilities (automatic discovery of new devices). Thank you – Enr Bel Oct 08 '17 at 12:13