title: JavaFX client server socket
body: <p>I'm setting a mail local service and I've built the server interface with JavaFX.</p>
  
  <p>The problem is that when I run the server, it shows the interface but it's blocked and it doesn't work in any way.</p>
  
  <p>It seems like only the graphics doesn't appear, the backend is working. Indeed if I connect the client and do a request, it all works.
  Is it maybe a problem of thread?</p>
  
  <p>This is the main:</p>
  
  <pre><code>FXMLLoader loader = new FXMLLoader(getClass().getResource("MainView.fxml"));
  Parent root = loader.load();
  
  stage.setTitle("Server Log");
  stage.setScene(new Scene(root, 490, 309));
  stage.centerOnScreen();
  stage.show();
  
  
  ServerModel m = new ServerModel(); //create Model
  ServerController c = loader.getController(); //get controller
  c.setModel(m);
  m.start(); //the problem is here, if I comment this line It shows the server interface but obviously the backend doesn't work.
  </code></pre>
  
  <p>The constructor of ServerModel is this:</p>
  
  <pre><code>public ServerModel() {
      try {
          serversocket = new ServerSocket(5888); 
      } catch (IOException e) {
          Logger.getLogger(ServerModel.class.getName()).log(Level.SEVERE, null, e);
      }
  }
  </code></pre>
  
  <p>and this is the start method of the model that attends the client request for socket:</p>
  
  <pre><code>public void start(){
      Socket socket = null;
      while (!closed){ //server main loop
          try{
              socket = serversocket.accept();
              //... (here there would be threads that communicate with client and set closed to true)
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>