title: Why socket does not connect with ip instead of localhost?
body: <p>I am trying to connect to server via ip address but it does not work. Both are in the same machine and when I change ipAddress to localhost it works. What would be the reason for that?</p>
  
  <pre><code>try {
      String ipAddress = "46.155.17.100";
      int port = 8082;
  
      // Create a socket to connect to the server
      socket = new Socket(ipAddress, port);
  
      toServer = new ObjectOutputStream(socket.getOutputStream());
  
      fromServer = new ObjectInputStream(socket.getInputStream());
  
  } catch (Exception ex) {
      connected = false;
      try {
          if (socket != null) {
              socket.close();
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
      return null;
  }
  </code></pre>
  
  <p>EDİT : When I change my connection from WiFi to internet cable, socket is connected with new ip address. But I dont know why :(</p>