1

I'm creating a client/server application that should work on LAN.

First with RMI the user register their i dont know what(IP?), this is the question :)

After that i create a ServerSocket and waiting for accept().

Now the client(or better, the server..that have the registered user) want to establish an connection but... what if the IP Address was changed ?

There is a way to "register something" on the server that if the IP change all continue to work?

I try to explain it better: i cant register an IP address and later connect on it, because if the IP change i lost the reference. I would like to register "something" that is idipendente from the IP.

Hope you have understand my question..

jww
  • 97,681
  • 90
  • 411
  • 885
Mistre83
  • 2,677
  • 6
  • 40
  • 77

2 Answers2

3

The answer is to use DNS. DNS is the appropriate de-referencing mechanism to obtain one or more IP addresses for a given name.

cpurdy
  • 1,177
  • 5
  • 12
  • 1
    could you give me an exaple ? – Mistre83 Mar 23 '15 at 19:09
  • If i use getInetAddresses().nextElement().getHostName() to get the hostname i get something like this fe80:0:0:0:7aca:39ff:febb:3b0b%en1 and when i create the socket this throws an exception: UnknownHostException: no such interface en1. I have my PC connected with LAN and the other PC is connected in Wifi (sure, they are on the same network) – Mistre83 Mar 23 '15 at 20:20
  • First, you don't need the host name. Just pass the InetAddress itself and the port number to the appropriate constructor: public Socket(InetAddress address, int port) – cpurdy Mar 24 '15 at 15:33
0

You should DNS, which can translate an hostname, to a specific IP address. Of course I suggest you to suo exception to verify if the host is alive. You have also other solution; you can set up a fixed ip in the LAN directly from the server, or from the page control of the router (if you are use the infrastructure in the LAN). If you plane to you it remotely, you will have to use the DDNS, where you can the DNS for a dynamic IP.

I love coding
  • 1,183
  • 3
  • 18
  • 47