Currently, I have a JavaFX Application running and working perfectly, but now I want to achieve communication via sockets with an external server which can command and demand information about the App.
I save information about the system in an instance of a class called Storage, then I want to receive commands from remote, in another thread running a TCP socket, to change these parameters in storage and then the App thread could update the graphics.
Currently, I am aware that only the App thread can update the graphics on the primary stage, but I am trying to share a reference to the storage unit within the App and the socket thread. This approach seems to be non-possible, or is it?
Could something like this work?
public class Main{
public static void main(String args[]) {
Storage storage = new Storage();
AppView appView = new AppView(storage);
/* Endpoint for remote communication */
Communicator communicator = new Communicator(storage);
communicator.start();
}
static class AppView extends Application(){
public AppView(Storage st){
storage = st;
launch();
}
public void start(Stage primaryStage){
// scene
}
Storage storage;
}
}
I've tried to run the communication endpoint on a secondary thread and on the primary thread, then moving the App to a secondary thread, but can't get it right.
I found a previous question similar: Make JavaFX Application non static
But the answers are not what i'm looking for.
Thanks for any help.