简体   繁体   中英

Java - Network application- Real-Time

What are recommended strategies for building Java application that will be run on "desktop", not in browser. Characteristics of the application would be:

1. Multiple application instances would be running on different machines
 2. Applications must communicate in real-time (if one user make changes,
in another application data must be refreshed)

you want to look into using sockets, TCP or UDP, and also figure out if you want a central authoritative server ( what if two users change the same thing in different ways, whose data is saved?)

read this article from Oracle/Java here Java Custom Networking

Do you want to create a networking application maybe? based on sockets and so on? Regarding your 2 questions, I have implemented that scenario some time ago and I am working in something similar for my job, it is not complex at all, but I will answer to you according the two issues that concern to you.

  1. Multiple application instances would be run on different machines.

If you are going to install an instance of the application in the people's desktop, I'd suggest to be very careful with "paths", do not hard code any path, since the resources loading will be dynamic.

Check carefully what is the network architecture in which your application will be installed. Maybe it is just a LAN, or maybe it will work in a big network and access through VPN, etc. Check what is the scenario.

Once you make sure your application works fine in different machines without any path conflict or resource loading conflict, you can export your jar, generate it using maven, ant, etc.

Also, if you want to move forward, you can create an installer using any Install wizard creation and create a batch file (.exe) for Windows or (.sh) for Linux distr. But these are only suggestions for the installation stage.

On the other hand, if you wanna execute the application as a Java desktop but using an URL to launch it, you can take a look to JNLP.

  1. Applications must communicate in real-time (if one user make changes, then other will be able to see that)

If you want to do that, you will need, for sure, a server to provide and store information. The server can be a physical machine set up in the office or a remote one.

You have two options here:

Use Java Networking: Create an application that works as a server that provides and saves the information (it should be a concurrent environment since many people will perform transactions or queries over it). Check how can you create a basic server - client application using Sockets to understand better how it works and then you will not have problems to add the complexity of the requirements your environment demands.

You can simply, develop a Java REST Based application and make your Client application connect to the machine (or machines if you plan to implement load balancing) and consume those REST. You can take a look to Jersey libraries in order to implement your scenario. Make sure to add security to these Web Services and make the server private access for the network in which your application instances will work.

Well, that's what I can tell you regarding the scenario you try to implement, based on what I've done and what I'm doing now so far.

Maybe if you need additional or further information, you can reply in the comments, and it will be great to help you.

Regards and happy coding :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM