1

我有 2 个进程需要通过同一台 PC 和不同的 PC 进行通信。在本地情况下,进程通信是在不同进程之间进行的,例如 ProcessA和 Process B
在远程情况下,它将是A在不同 PC 上运行的 2 个 Process 实例之一。
我将从头开始创建它们,我想知道最好的方法是什么。我知道 RMI 和套接字,但我想知道我所描述的情况,并且还考虑到交换的消息很小并且 API 的数量非常少,如果有一个标准的方法/库的话。
任何建议都非常受欢迎

@EJP 评论后更新:
我的兴趣是 1)以轻松的方式实现通信要求,因为暴露的 API 非常小,消息也会如此 2)如果可能的话,使用和学习一个新的流行框架(我已经知道 RMI和插座)

4

5 回答 5

4

如果您只是在寻找消息传递框架,那么有很多可用的,例如

But when you use a 3rd party framework, you are then adding an additional dependency to your application. If it is something very simple like your case, perhaps writing a TCP client/server would be sufficient for a client/server paradigm or if you are looking for publisher/subscriber paradigm then you can look into using UDP multicast. You just need your data class to extends Serializable if you want to be able to marshal and unmarshal your data to buffer and send it over to network using typical JAVA socket API.

于 2013-01-11T07:44:49.327 回答
2

我强烈建议看看 Thrift。在我使用过的所有技术(Web 服务、RMI、XML-RPC、Corba)中,它是我目前最喜欢的。基本上涉及的步骤是:

  1. 下载 Thrift 编译器。
  2. 添加 Maven 依赖项(确保它与编译器版本相同!)我目前使用 0.8.0。
  3. 编写你的 Thrift IDL(非常简单,google 一下,因为有很多例子)。
  4. 为 Java 编译它。
  5. 编写您的服务器/客户端。

通常,您可以用大约 30 行代码将服务器和客户端组合在一起。在速度和可靠性方面,它从来没有让我失望过。

于 2013-01-11T07:28:05.053 回答
0

JMX是一个不错的选择。

例子 :

http://www.javalobby.org/java/forums/t49130.html

IMB JMX 示例

http://alvinalexander.com/blog/post/java/source-code-java-jmx-hello-world-application

于 2013-01-11T07:23:26.960 回答
0

You might have a look at Versile Java (full disclosure: I am one of the developers), it satisfies at least your criteria #1. From the API documentation, here are some examples of writing remote-enabled objects, running a service, and connecting to a service.

于 2013-01-11T10:10:19.317 回答
0

If you want to learn something new then I'd look at OpenSplice. The reason is pretty simple, among the technologies suggested above is the only one that provides you with Data-Centric abstractions.

The cool thing about OpenSplice is that gives you the abstraction of a Global Data Space, yet the implementation of this global data space is fully distributed and very high performance.

Take a look at some of the slides available at http://www.slideshare.net/angelo.corsaro and I am sure you'll get in love with the technology.

Finally OpenSplice is Open Source.

Happy Hacking.

A+

于 2013-04-26T10:18:11.543 回答