简体   繁体   English

Java-网络应用程序-实时

[英]Java - Network application- Real-Time

What are recommended strategies for building Java application that will be run on "desktop", not in browser. 建议使用哪些策略来构建将在“桌面”而不是浏览器中运行的Java应用程序。 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?) 您想研究使用套接字,TCP还是UDP,并弄清楚是否要使用中央权威服务器(如果两个用户以不同的方式更改同一件事,并保存其数据该怎么办?)

read this article from Oracle/Java here Java Custom Networking 在此处阅读Oracle / Java的这篇文章Java自定义网络

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. 也许它只是一个LAN,或者它可以在大型网络中工作并通过VPN等访问。请检查情况。

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. 一旦确保您的应用程序可以在不同的机器上正常运行而没有任何路径冲突或资源加载冲突,就可以导出jar,使用maven,ant等生成它。

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. 另外,如果要继续前进,则可以使用任何安装向导创建来创建安装程序,并为Windows创建一个批处理文件(.exe)或为Linux distr创建一个批处理文件(.sh)。 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. 另一方面,如果您想将应用程序作为Java桌面执行,但使用URL来启动它,则可以看看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). 使用Java网络:创建一个用作服务器的应用程序,该服务器提供并保存信息(它应该是并发环境,因为许多人将在该环境上执行事务或查询)。 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. 检查如何使用Sockets创建基本的服务器-客户端应用程序,以更好地了解其工作方式,然后您将不会遇到增加环境所要求的复杂性的问题。

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. 您可以简单地开发一个基于Java REST的应用程序,并使您的Client应用程序连接到计算机(如果您打算实现负载平衡,则连接到计算机)并使用这些REST。 You can take a look to Jersey libraries in order to implement your scenario. 您可以看一下Jersey库来实现您的方案。 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. 确保为这些Web服务添加安全性,并使服务器私有访问您的应用程序实例将在其中运行的网络。

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 :) 问候和愉快的编码:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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