title: Java Server/Client for two computers
body: <p>I am creating a chat between multiple computers, but i cannot find <b>how to connect a socket to a serverSocket</b> that <b>is not in the client's computer</b>.<br></p>
  
  <p>P.S. I am new of socket programming.</p>
  
  <hr>
  
  <p>This is server</p>
  
  <pre><code>package chat;
  
  import java.io.*;
  import java.net.*;
  import java.util.*;
  
  public class Server {
  
      public List&lt;String&gt; names = new ArrayList&lt;String&gt;();
      public HashMap&lt;String, Socket&gt; sockets = new HashMap&lt;String, Socket&gt;();
      public HashMap&lt;String, BufferedReader&gt; inputs = new HashMap&lt;String, BufferedReader&gt;();
      public HashMap&lt;String, PrintWriter&gt; outputs = new HashMap&lt;String, PrintWriter&gt;();
  
      public void start() throws IOException {
          int port = 2019;
          ServerSocket serverSocket = new ServerSocket(port);
  
          System.out.println("Server started");
          while(true) {
              System.out.println("\nLooking for new channels in the subspace.");
              Socket socket = serverSocket.accept();
              BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
              PrintWriter output = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);
  
              System.out.println("Someone connected.");
  
              new Thread() {
                  public void run() {
                      //various input/output operations
                  }
              }.start();
          }
      }
  
      public static void main(String[] args) throws IOException {
          Server server = new Server();
          server.start();
      }
  }
  </code></pre>
  
  <hr>
  
  <p>this is Client</p>
  
  <pre><code>package chat;
  
  import java.io.*;
  import java.net.*;
  
  public class Client {
  
      public Socket socket;
      public BufferedReader input;
      public PrintWriter output;
  
      public void start() throws IOException {
          String host = "192.168.1.4 / 127.0.0.1 / computer's global ip";
          int port = 2019;
          socket = new Socket(host, port);
          input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
          output = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);
  
          System.out.println("Successfully established connection to " + host + ":" + port);
  
          new Thread() {
              public void run() {
                  //output operations
              }
          }.start();
  
          new Thread() {
              public void run() {
                  //input operations
              }
          }.start();
      }
  
      public static void main(String[] args) throws IOException {
          Client client = new Client();
          client.start();
      }
  }
  </code></pre>
  
  <hr>
  
  <p>Now, the problem is that <b>this works when server and client are on the same pc</b>.<br>
  I sent to my other computer a copy of the client file but when i insert the ip of the server's computer (192.168.1.4) nothing happens.<br>
  Both computers are connected <b>to the same WI-FI</b>.<br>
  <br>
  Another question is: how to connect 2 computers without the same WI-FI?</p>