MVC JavaFX Chat Application - Where should the socket code be?

I'm trying to employ an MVC architecture to a simple multi threaded client-server chat program. However, on the clientside, I'm unsure where the code 'which connects to a socket' and reads messages from the server should be, in the controller of the fxml view (handles the events) or the model (stores data about the chat) or the program which launches the whole program (creates the scene and stage, loads the fxml and shows the scene and stage).

I'm trying to clear up on my MVC understanding :P

1 answer

  • answered 2018-05-16 06:50 seb

    The Model (lets call it ChatModel) part could contain javafx.beans.Property<ChatLine> or a javafx.collections.ObservableList<ChatLine>. Then your view controller will listen to this property or list change and update the view object. This is the MVC part. Then your communication layer will open the chat socket and update the ChatModel.