0

I'm coding an app which consist of two pieces. Desktop and android. There is one desktop and several android devices. (don't know the count.) I want to communicate android devices between desktop with TCP. However, android devices doesn't know desktop's lan ip address.

I thouht 2 ways:

1-Desktop app changes the local ip address on start. So android devices know the ip address. (I coded with that ip address)

2-Desktop app always tries to connect ip addresses (192.168.0.1 - 192.168.0.255) to sent desktop's ip address. And when an android device connect to the network accept the connection then know desktop's ip.

But there is some problems in both ways.

On first, you must be administrator to changing lan ip. So run command as admin with java is a problem. Because if I do this, when user start the program, uac always asks for it.

On second, I think there will be performance issues because of app always tries to connect. Exept this, when android device connect and dhcp gives it 192.168.0.5 , but loop is on 192.168.0.150. So android device have to wait for connection.

Is there a better way than these?

2 Answers2

1

Look at this post Network discovery in Java using multicasting I think this would be the best way to do it.

  1. The server will listen for a broadcast message from client
  2. the client sends a broadcast request asking for server ip
  3. server receives request and replies back with server ip.
Community
  • 1
  • 1
gregor2004ua
  • 159
  • 8
  • but if ap isolation is enable, devices can not reach each other with udp. I tried to broadcast over tcp but it is so slow. –  Apr 28 '16 at 20:49
0

You can use the hostname. If the network is properly configured, the host name will point to the correct ip even if it changes

  • If wrong please correct. Desktop app will set a hostname for ex. "blabla" and all android devices will try to connect "blabla:port". right? –  Apr 27 '16 at 15:56