如何让一个Java程序与另一个Java程序通信

huangapple go评论100阅读模式
英文:

How to let a java program comunicate with a different java program

问题

我正试图构建一个系统,可以在多个Minecraft服务器之间平衡玩家负载并创建新的Minecraft服务器。我制作了一个插件来平衡玩家,并且它运行得非常好。但是现在我想创建一个系统,根据从插件接收到的数据来创建新的服务器。

这个系统与插件完全分开。但是我应该如何让插件发送某种命令给服务器系统,以便让它知道要创建一个新的服务器呢?我已经研究过套接字(Sockets),但想知道这是否是最佳解决方案。或许使用 REST API 也可以?

英文:

I am trying to build a system that loadbalances minecraft players across multiple servers and creates new minecraft servers. I made a plugin to loadbalance players and it works like a charm. But now I want to make a system that creates new servers based on the data it receives from the plugin.

This system is completely seperate from the plugin. But how do I make it so the plugin sends some sort of command to the server system so it knows to create a new server. I have looked into Sockets but was wondering if this is the best solution. Maybe a Rest api will work aswell?

答案1

得分: 1

依据我的观点,最佳解决方案是基于自定义协议的套接字,这将比使用HTTP或其他协议更加高效。我建议使用我编写的这个轻量级套接字库 - Sonder。它直接在套接字上使用nio进行操作。

英文:

In my opinion the best solution is sockets based on your own protocol, it will be much more productive, than http or something else.
I can suggest using this lightweight socket library written by me -
Sonder.
It's working directly on sockets using nio.

1: https://github.com/tix320/sonder "Sonder"

答案2

得分: -2

你可以通过一个Java程序将内容写入一个.txt文件,然后另一个程序使用java.io.FileWriter和java.util.Scanner读取行,然后删除命令。我在GitHub上有一个项目,可以在这里找到:

> https://github.com/DPS100/Diego-s-Project-Euler/blob/master/Main.java

英文:

You could solve this by having one java program write to a .txt file and another program read the line then delete the command using java.io.FileWriter and java.util.Scanner. I have a github project that does this here:

> https://github.com/DPS100/Diego-s-Project-Euler/blob/master/Main.java

huangapple
  • 本文由 发表于 2020年5月31日 06:24:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/62109362.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定