您应该开始在 Google 上搜索“使用 Java 的 Rest Services”或类似的内容。
您需要一些中央组件来管理您的两个 android 游戏会话的游戏状态。例如,您有一个 url,就像localhost://myService/Dice
您将POST
掷新骰子一样。如果其他人GET
对该资源进行了操作,他将能够取回您在游戏期间发布的掷骰子。如果您不希望玩家能够进行交互,您可以在玩家POST
无法做到这一点时禁止玩家使用新骰子,并且 GUI 应该以某种方式反映这一点。也许在您发布骰子或类似的东西后禁用按钮。
它还有更多内容,但这应该让你以某种方式开始。
https://docs.oracle.com/javaee/6/tutorial/doc/gilik.html
上面 url 中的重要代码部分将是这样的 hello world:
package com.sun.jersey.samples.helloworld.resources;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.Path;
// The Java class will be hosted at the URI path "/helloworld"
@Path("/helloworld")
public class HelloWorldResource {
// The Java method will process HTTP GET requests
@GET
// The Java method will produce content identified by the MIME Media
// type "text/plain"
@Produces("text/plain")
public String getClichedMessage() {
// Return some cliched textual content
return "Hello World";
}
}