Why is my software locking up when connecting a Java Socket to a ServerSocket?When to use LinkedList over...

Is it idiomatic to construct against `this`

a sore throat vs a strep throat vs strep throat

How to have a sharp product image?

Is this homebrew Wind Wave spell balanced?

Why does Mind Blank stop the Feeblemind spell?

Elements other than carbon that can form many different compounds by bonding to themselves?

Why didn't the Space Shuttle bounce back into space as many times as possible so as to lose a lot of kinetic energy up there?

How did Captain America manage to do this?

Get consecutive integer number ranges from list of int

Re-entry to Germany after vacation using blue card

Do I have an "anti-research" personality?

555 timer FM transmitter

"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?

Apply MapThread to all but one variable

As an international instructor, should I openly talk about my accent?

Implications of cigar-shaped bodies having rings?

Two field separators (colon and space) in awk

Does Gita support doctrine of eternal samsara?

How come there are so many candidates for the 2020 Democratic party presidential nomination?

Should the Death Curse affect an undead PC in the Tomb of Annihilation adventure?

Why did C use the -> operator instead of reusing the . operator?

Phrase for the opposite of "foolproof"

How to limit Drive Letters Windows assigns to new removable USB drives

"The cow" OR "a cow" OR "cows" in this context



Why is my software locking up when connecting a Java Socket to a ServerSocket?


When to use LinkedList over ArrayList in Java?How does the socket API accept() function work?Why does Java have transient fields?How wait a ServerSocket connection on client SocketJava + ServerSocket + FirewallJava Socket/Serversocket WAN ConnectionJava the difference of Socket and ServerSocket in using portWhy is executing Java code in comments with certain Unicode characters allowed?Why is the Socket provided by ServerSocket using a different port?ServerSockets connecting to client






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm running a multithreaded server that handles the connection of multiple clients. The server-client interaction works without issue when the clients connect using the 'localhost' address. But when using the IP-address of the server the software stops responding after creating the Socket on the client side even if the client is running on the host computer.



CLIENT SIDE:



System.out.println("Connecting to server " + ip + ":" + port + " ... ");
if(socket == null || socket.isClosed()) {
try {
System.out.println("Socket is closed. Creating new socket.");
socket = new Socket(InetAddress.getByName(ip), port); // This is the point where the client gets stuck when using an IP-address. Using "localhost" works fine.
System.out.println("Created new socket");
try {
System.out.println("Attempting to create new streams");
oos = new ObjectOutputStream(socket.getOutputStream());
ois = new ObjectInputStream(socket.getInputStream());
System.out.println("Created new streams");
} catch (IOException e) {
e.printStackTrace();
System.out.print("Could not connect socket streams");
disconnect();
return false;
}
System.out.print("Successfully connected to server...");
start();
return true;
} catch (Exception e) {
System.out.print("Cannot connect to server");
e.printStackTrace();
return false;
}
}


SERVER SIDE:



    public Server(int port, ServerController controller) throws IOException {

this.controller = controller;
try {
serversocket = new ServerSocket(port);
server.start();
} catch (IllegalArgumentException e) {}

this.port = serversocket.getLocalPort();
}

public void run() {
System.out.println("MessengerServer running, port " + serversocket.getLocalPort());
while(!serversocket.isClosed()) {
try {
Socket socket = serversocket.accept();
tempClient = new ClientHandler(socket, controller);
clients.add(tempClient);
} catch(IOException e) {
}
}
}









share|improve this question













migrated from superuser.com yesterday


This question came from our site for computer enthusiasts and power users.

























    0















    I'm running a multithreaded server that handles the connection of multiple clients. The server-client interaction works without issue when the clients connect using the 'localhost' address. But when using the IP-address of the server the software stops responding after creating the Socket on the client side even if the client is running on the host computer.



    CLIENT SIDE:



    System.out.println("Connecting to server " + ip + ":" + port + " ... ");
    if(socket == null || socket.isClosed()) {
    try {
    System.out.println("Socket is closed. Creating new socket.");
    socket = new Socket(InetAddress.getByName(ip), port); // This is the point where the client gets stuck when using an IP-address. Using "localhost" works fine.
    System.out.println("Created new socket");
    try {
    System.out.println("Attempting to create new streams");
    oos = new ObjectOutputStream(socket.getOutputStream());
    ois = new ObjectInputStream(socket.getInputStream());
    System.out.println("Created new streams");
    } catch (IOException e) {
    e.printStackTrace();
    System.out.print("Could not connect socket streams");
    disconnect();
    return false;
    }
    System.out.print("Successfully connected to server...");
    start();
    return true;
    } catch (Exception e) {
    System.out.print("Cannot connect to server");
    e.printStackTrace();
    return false;
    }
    }


    SERVER SIDE:



        public Server(int port, ServerController controller) throws IOException {

    this.controller = controller;
    try {
    serversocket = new ServerSocket(port);
    server.start();
    } catch (IllegalArgumentException e) {}

    this.port = serversocket.getLocalPort();
    }

    public void run() {
    System.out.println("MessengerServer running, port " + serversocket.getLocalPort());
    while(!serversocket.isClosed()) {
    try {
    Socket socket = serversocket.accept();
    tempClient = new ClientHandler(socket, controller);
    clients.add(tempClient);
    } catch(IOException e) {
    }
    }
    }









    share|improve this question













    migrated from superuser.com yesterday


    This question came from our site for computer enthusiasts and power users.





















      0












      0








      0








      I'm running a multithreaded server that handles the connection of multiple clients. The server-client interaction works without issue when the clients connect using the 'localhost' address. But when using the IP-address of the server the software stops responding after creating the Socket on the client side even if the client is running on the host computer.



      CLIENT SIDE:



      System.out.println("Connecting to server " + ip + ":" + port + " ... ");
      if(socket == null || socket.isClosed()) {
      try {
      System.out.println("Socket is closed. Creating new socket.");
      socket = new Socket(InetAddress.getByName(ip), port); // This is the point where the client gets stuck when using an IP-address. Using "localhost" works fine.
      System.out.println("Created new socket");
      try {
      System.out.println("Attempting to create new streams");
      oos = new ObjectOutputStream(socket.getOutputStream());
      ois = new ObjectInputStream(socket.getInputStream());
      System.out.println("Created new streams");
      } catch (IOException e) {
      e.printStackTrace();
      System.out.print("Could not connect socket streams");
      disconnect();
      return false;
      }
      System.out.print("Successfully connected to server...");
      start();
      return true;
      } catch (Exception e) {
      System.out.print("Cannot connect to server");
      e.printStackTrace();
      return false;
      }
      }


      SERVER SIDE:



          public Server(int port, ServerController controller) throws IOException {

      this.controller = controller;
      try {
      serversocket = new ServerSocket(port);
      server.start();
      } catch (IllegalArgumentException e) {}

      this.port = serversocket.getLocalPort();
      }

      public void run() {
      System.out.println("MessengerServer running, port " + serversocket.getLocalPort());
      while(!serversocket.isClosed()) {
      try {
      Socket socket = serversocket.accept();
      tempClient = new ClientHandler(socket, controller);
      clients.add(tempClient);
      } catch(IOException e) {
      }
      }
      }









      share|improve this question














      I'm running a multithreaded server that handles the connection of multiple clients. The server-client interaction works without issue when the clients connect using the 'localhost' address. But when using the IP-address of the server the software stops responding after creating the Socket on the client side even if the client is running on the host computer.



      CLIENT SIDE:



      System.out.println("Connecting to server " + ip + ":" + port + " ... ");
      if(socket == null || socket.isClosed()) {
      try {
      System.out.println("Socket is closed. Creating new socket.");
      socket = new Socket(InetAddress.getByName(ip), port); // This is the point where the client gets stuck when using an IP-address. Using "localhost" works fine.
      System.out.println("Created new socket");
      try {
      System.out.println("Attempting to create new streams");
      oos = new ObjectOutputStream(socket.getOutputStream());
      ois = new ObjectInputStream(socket.getInputStream());
      System.out.println("Created new streams");
      } catch (IOException e) {
      e.printStackTrace();
      System.out.print("Could not connect socket streams");
      disconnect();
      return false;
      }
      System.out.print("Successfully connected to server...");
      start();
      return true;
      } catch (Exception e) {
      System.out.print("Cannot connect to server");
      e.printStackTrace();
      return false;
      }
      }


      SERVER SIDE:



          public Server(int port, ServerController controller) throws IOException {

      this.controller = controller;
      try {
      serversocket = new ServerSocket(port);
      server.start();
      } catch (IllegalArgumentException e) {}

      this.port = serversocket.getLocalPort();
      }

      public void run() {
      System.out.println("MessengerServer running, port " + serversocket.getLocalPort());
      while(!serversocket.isClosed()) {
      try {
      Socket socket = serversocket.accept();
      tempClient = new ClientHandler(socket, controller);
      clients.add(tempClient);
      } catch(IOException e) {
      }
      }
      }






      networking java






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      JoelJoel

      1




      1




      migrated from superuser.com yesterday


      This question came from our site for computer enthusiasts and power users.









      migrated from superuser.com yesterday


      This question came from our site for computer enthusiasts and power users.


























          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55852564%2fwhy-is-my-software-locking-up-when-connecting-a-java-socket-to-a-serversocket%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55852564%2fwhy-is-my-software-locking-up-when-connecting-a-java-socket-to-a-serversocket%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Why not use the yoke to control yaw, as well as pitch and roll? Announcing the arrival of...

          Couldn't open a raw socket. Error: Permission denied (13) (nmap)Is it possible to run networking commands...

          VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...