Java jar应用程序和java web应用程序的通信和实现
我有一个用 Java 编写的多人游戏服务器应用程序,当玩家客户端通过套接字加入多人游戏时,该应用程序会连接到玩家客户端。服务器应用程序(在 JVM 中运行的 JAR)正在侦听来自客户端的传入连接的端口(例如 9999)。
我想添加一个网站来监控整个项目,其中包含从正在运行的游戏服务器获取的信息。一种方法是打开从站点到游戏服务器 (Java) 的套接字(例如 PHP 套接字),并实现自定义协议以从服务器获取数据。但这种方法非常耗时,因为我需要添加对要传递到监控网站的每种数据类型的支持。
我在想是否有一种方法可以用 Java 编写网站并通过直接链接与我的游戏服务器进行通信。我认为 RMI 是一个解决方案,因为我的 JAR 和 WAR 都可以通过它进行通信,但是是否有更好的方法可以在同一个 JAR 文件中构建 Web 应用程序和游戏服务器应用程序?那么当我的游戏服务器运行时,Web 应用程序也会运行吗?
I have a multiplayer game server application written in Java which connects to player clients when they join the multiplayer game via a socket. The server application (a JAR running in the JVM) is listening to a port (e.g. 9999) for incoming connections from clients.
I want to add a website to minitor the entire project which contains information taken from the running game server(s). One way would be to open a socket from the site (a PHP socket for example) to the gameserver (Java) and implement a custom protocol for taking data from the server. But that method is time consuming as I need to add support for each type of datum I want to pass to the monitoring website.
I was thinking if there is a way to write the site in Java and simply communicate with my gameserver via a direct link. RMI would be a solution I assume since both my JAR and my WAR can communicate through it, but isn't there some better way to build both the web application and the gameserver application inside the same JAR file? So that when my gameserver runs, the web application runs too?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,这是拥有管理控制台的最快方法。只需将您的服务器转换为战争应用程序,其中包含带有用于客户端的开放套接字的游戏服务器和管理页面。要启动您的服务器,只需将其放入 tomcat 中即可。
一种不需要一些自行创建的协议的更简洁的方法是让您的服务器对您想要管理的所有关键对象使用 mbean。但这需要一些编码。
干杯,斯文
this looks to me as the fastest way to have an admin console. Just transform your server into a war application which contains both your game server with an open socket for clients and your administration pages. To start your server simply drop it into a tomcat.
A cleaner approach which does not require some self-created protocol would be to have your server use mbeans for all key objects which you would like to admin. But this needs some coding.
Cheers, Sven
您的游戏服务器中应该有一个嵌入式 Web 服务器。尝试 Jetty (http://jetty.codehaus.org/jetty/)。它很容易嵌入到任何 Java 应用程序中。
You should have an embedded web server in your game server. Try Jetty (http://jetty.codehaus.org/jetty/). It's quite easy to embed in any java application.