socket communications in JFX

Daniel Zwolenski zonski at
Sun Aug 12 21:14:14 PDT 2012

Hey Jose,

I will reply properly later when I get home, but in general you can do
normal Java socket stuff in JFX2.

I wouldn't use the Task/Worker stuff for this but make use of the low-level
Platform.runLater method.

i.e. Start a new thread that reads from the thread, when you get some data
you want to process just use Platform.runLater()


new Thread() {

   run() {

    while (data = socket.readNext()) {

        Platform.runLater(new Runabble() {
            // update JavaFX UI with 'data' read from socket




On Mon, Aug 13, 2012 at 11:53 AM, Jose Martinez <jmartine_1026 at>wrote:

> Jonathon,
> Thank you.  I will digest this info and respond back with any questions.
> jose
> ________________________________
>  From: Jonathan Giles <jonathan.giles at>
> To: openjfx-dev at
> Sent: Sunday, August 12, 2012 9:33 PM
> Subject: Re: socket communications in JFX
> The generally accepted approach is to keep the slow running tasks off of
> the UI thread (in our case the JavaFX Application Thread). If you don't,
> you subject the user to a slow user interface, but I'm sure you're well
> aware of this based on your comments.
> Generally how you approach this is not defined by JavaFX, rather it comes
> down to how your architecture needs to work. One place to look is the
> JavaFX Worker and Task API:
> -- Jonathan
> On 13/08/2012 1:27 p.m., Jose Martinez wrote:
> > Hello,
> >
> > I am preparing to implement multiplayer capabilities.  Saw one or two
> articles out there about socket communications and JFX but they were from
> JFX 1.x.
> >
> > I guess my first question is, is there a way to communicate from a
> socket thread directly to the JFX main thread or does the JFX main thread
> need to poll some shared object?  Is there any recent documentation out
> there on either the topic of socket communications within JFX or even just
> multithreading in JFX applications?
> >
> > thanks!
> > jose

More information about the openjfx-dev mailing list