I'm trying to create a terminal emulator with pty.js and xterm.js. I've never tried something like this before so If I say something wrong, I apologize, its because I didn't understand it correctly. Anyway, The terminal should be displayed inside a JavaFX WebView
and all the GUI is ready and tested. From what I've found, I understood that there must be a server running on localhost in order for pty.js to spawn a shell there, and communicate the results through xterm.js on the WebView
. Now, I'm trying to create a server using ServerSocket
in a new Thread
but when I test the application and click on the Terminal button, the application freezes. I've tested the server whether it is running or not by visiting my localhost and it was up and running. So, what I get is that the main Thread of the application takes a lower priority the moment the Server thread starts. Am I right? And if so, how can I solve this?
The below function is called in the initialize
method of the Terminal scene which is loaded from the main controller. Can somebody please explain why is this happening?
private void createServerToSpawnPty() {
Thread thread = new Thread(() -> {
try {
ServerSocket server = new ServerSocket(8080);
System.out.println("Created Java localhost server on port: 8080");
while (true) {
final Socket client = server.accept( );
System.out.println("client connected:+
client.isConnected( ));
}
}catch (IOException exception) {
exception.printStackTrace( );
}
});
thread.setDaemon(true);
thread.run();
}