Socket JAVA not local

1

I have an application where I open a socket;

server = new ServerSocket(25000, 1, InetAddress.getByName("localhost"));

And a client that connects to him;

private Socket socket;
this.socket = new Socket("localhost", 25000);

The program works perfectly in local, my question is, how could I do to communicate the program in different computers? I have to pass the client the IP address of the server if or if, or there is some way that I can do it automatically ?

The objective would be not to make the user enter the IP address of the server, since it is not practical or easy for the User.

    
asked by Hector Lopez 22.02.2018 в 12:39
source

1 answer

1

You have not given many details about how your project is set up, but ultimately you need the client program to know the IP of your server in advance: While you are doing the development / testing, you can use localhost or the actual IP of your machine, but if that program comes to have a real use:

  • If the server has a fixed IP, you can put it with a constant in the client program.

  • If the server is going to be in a network of a company or with a public IP on the Internet, it is possible that the IP can be associated to a domain through a DNS.

Other more complex solutions would be for the client to connect to another server with fixed IP and obtain the IP of your server.

    
answered by 22.02.2018 / 12:55
source