Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8478235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:41:25+00:00 2026-06-10T18:41:25+00:00

I’m implementing an JavaFX application which is communicating with a mobile phone via wifi

  • 0

I’m implementing an JavaFX application which is communicating with a mobile phone via wifi (android).

Therefore I have a server thread on the JavaFX running in a background process:

public class NetworkService implements Runnable { 

    private final ServerSocket serverSocket;
    private final ExecutorService pool;

    private RoutePlannerJFX application;
    private UserData userData;


    public NetworkService(ExecutorService pool,
                          ServerSocket serverSocket,
                          RoutePlannerJFX app,
                          UserData data) {
        this.serverSocket = serverSocket;
        this.pool = pool;
        application = app;
        userData = data;
    }


    public void run() {
        try {
            while ( true ) {
                Socket cs = serverSocket.accept(); 
                pool.execute(new Handler(serverSocket, cs, application, userData));
            }
        } catch (IOException ex) {
            System.out.println("--- Interrupt NetworkService-run");
        }
        finally {
            System.out.println("--- Ende NetworkService(pool.shutdown)");
            pool.shutdown();  //keine Annahme von neuen Anforderungen
            try {
                pool.awaitTermination(4L, TimeUnit.SECONDS);
                if ( !serverSocket.isClosed() ) {
                    System.out.println("--- Ende NetworkService:ServerSocket close");
                    serverSocket.close();
                }
            } catch ( IOException e ) { }
            catch ( InterruptedException ei ) { }
        }
    }
}

which has a handler:

public class Handler implements Runnable {

    private final Socket client;
    private final ServerSocket serverSocket;

    private RoutePlannerJFX application;
    private UserData userData;


    Handler(ServerSocket serverSocket,Socket client, RoutePlannerJFX app, UserData data) {
        this.client = client;
        this.serverSocket = serverSocket;
        application = app;
        userData = data;
    }


    public void run() {
        StringBuffer sb = new StringBuffer();
        PrintWriter out = null;
        try {
            System.out.println( "running service, " + Thread.currentThread() );
            out = new PrintWriter( client.getOutputStream(), true );
            BufferedReader bufferedReader = 
                new BufferedReader(
                    new InputStreamReader(
                        client.getInputStream()));
            char[] buffer = new char[100];
            int anzahlZeichen = bufferedReader.read(buffer, 0, 100); 
            String nachricht = new String(buffer, 0, anzahlZeichen);
            String[] werte = nachricht.split("\\s");


            System.out.println(nachricht+"\n");

            POI poi = new POI(nachricht);
            userData.addItemToPoiList(poi);

            application.setScene("INSTRUCT");

        } catch (IOException e) {System.out.println("IOException, Handler-run");}
        finally { 
            System.out.println(sb);  //Rückgabe Ergebnis an den Client
            if ( !client.isClosed() ) {
            System.out.println("****** Handler:Client close");
            try {
                client.close();
                } catch ( IOException e ) { }
            } 
        }
    }
}

The application has a public method to change the scene (setScene()).

That’s the way I wish I could do it, but now I know, that I cannot switch the scene in my backgroundprocess.

Has anyone an idea how to implement this problem? I need to fire an action, when my backgroundprocess receives a message from the the client, but I don’t know what’s the best way to do that… I already found javafx.concurrent, but which do I have to use and how?

Thank’s in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:41:26+00:00Added an answer on June 10, 2026 at 6:41 pm

    For the client side you can use either a Task or a Service to run in a separate thread & update the GUI as described in the documentation

    You can check this post too JavaFX Async Task

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have an autohotkey script which looks up a word in a bilingual dictionary
I have a text area in my form which accepts all possible characters from
I have an array which has BIG numbers and small numbers in it. I
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.