I write client server application (chat). The client sends a message -> the server accepts it and sends it to all other clients. Initially, I just made the Label update with messages (via Task) and everything worked fine. Now we need another 1 Label to display the list of connected clients, the server sends a string with information in the following form: "/тип/сообщение" for example "/m/hello!" this is a hello message. "/n/User" means that a new user has been connected with User. How to make that when receiving a string from the server, the client updates a specific Label depending on the type of message?

  • know what is MVC? that's what you need to implement. your model should change and the view should use data from the model. - Mikhail Vaysman
  • I’m what mvc is, the problem is different, updating the label is obtained only in the method where the scene was created, but still the problem is in another way: until the server sends the label line it will wait for this line and eventually hang. everything would be easily solved if the line was received from the server and the label update was in a separate thread, but javafx does not allow this - Ula La
  • one
    MVC is a pattern. Yes, UI updates are possible only from the UI stream, but this is easily solved - Platform.runLater - Mikhail Vaysman
  • Well, most likely this is the right decision (because everywhere they write it), but I cannot find a working implementation variant, since The code that I find in google doesn't work. Can you jot down a sample code? - Ula La
  • right I know a little about it. here's an option for swing, but it's not difficult to refine for javafx. - Mikhail Vaysman

0