简体   繁体   English

Java TCP / IP应用程序将被分发

[英]Java TCP/IP Application To Be Distributed

I have developed an application using TCP/IP where the application is a listener. 我已经使用TCP / IP开发了一个应用程序,其中该应用程序是侦听器。 When messages arrive on a ServerSocket, the application further processes the message. 当消息到达ServerSocket时,应用程序将进一步处理消息。

This is deployed onto a Glassfish server. 将其部署到Glassfish服务器上。 This application now needs to be turned distributed meaning two instances of the application on Glassfish and data to be sent to each instance's listener on different ports. 现在需要将该应用程序转换为分布式,这意味着该应用程序在Glassfish上的两个实例以及要发送到不同端口上每个实例的侦听器的数据。 How can this be achieved ? 如何实现呢? Will there be code changes to be applied? 会有代码更改要应用吗? The port number the application listens to is specified in a properties file. 应用程序侦听的端口号在属性文件中指定。

Usually RMI is used, but for TCP/IP applications I am not sure. 通常使用RMI,但不确定TCP / IP应用程序。

Assuming that you've already implemented your application, and figured out how to deploy it to Glassfish, then you could potentially deploy it twice with two copies of the same WAR file (?) ... differing only in having properties files with different properties. 假设您已经实现了应用程序,并弄清楚了如何将其部署到Glassfish,那么您可能会使用同一WAR文件的两个副本(?)对其进行两次部署...仅在使属性文件具有不同的属性方面有所不同。

On the other hand, you could also change the code so that a single application runs two different listener threads that listen on the two different ports. 另一方面,您也可以更改代码,以便单个应用程序运行两个不同的侦听器线程,这些线程在两个不同的端口上侦听。

Either way, you need to end up with two listener threads. 无论哪种方式,您都需要以两个侦听器线程结束。

Depending on which approach you take, code changes may be required. 根据您采用的方法,可能需要更改代码。


I'm a bit puzzled as to why you are using a Java EE application server to run something that seems to be just requiring vanilla Java sockets. 对于您为什么使用Java EE应用程序服务器运行似乎只需要原始Java套接字的东西,我有些困惑。 Does the application make use of Java EE functionality in other ways? 应用程序是否以其他方式使用Java EE功能? If not, it would be better to just to leave it as a Java SE application, and run it directly using the java command. 如果不是,最好将其保留为Java SE应用程序,然后直接使用java命令运行它。 (One or two JVMs ... as required.) (根据需要,一个或两个JVM。)

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

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