问题描述
我有一个 JavaFX 桌面应用程序,它运行具有 websockets 的嵌入式 Spark 服务器。当我运行桌面应用程序时,它会在本地主机上创建一个随机的 url 路径(即 localhost:4567/someRandomUrl)。
但是,我希望我的 JavaFX 桌面应用程序创建这个 url,其中包含一个不在本地主机上而是在 linux 服务器上的 web 套接字。因此,如果我的服务器的 ip 是 1.1.1.1 并且有人在他们的本地机器上将应用程序作为 JavaFX 运行,它将创建这个随机链接 1.1.1.1/someRandomUrl,他们可以在那里使用他们的手机/平板电脑/等与应用程序进行交互。
我该怎么做才能使 Spark 无法在本地主机和我的 linux 服务器上运行?
public class Main {
private static String linkPath;
public static void main(String[] args) {
// creates a unique link
linkPath = sparkUtil.generaterandomStringSequence();
// initializes web sockets
Spark.webSocket("/websocket/" + linkPath,EchoWebSocket.class);
// creates the page to send request to the frontend
// linkPath variable is the unique link. someRandomUrl in the example
// quiz is the html file that would show up when you see
Spark.get(linkPath,((request,response) -> {
HashMap<String,Object> model = new HashMap<>();
ModelAndView modelAndView = new ModelAndView(model,"quiz");
return new ThymeleafTemplateEngine().render(modelAndView);
}));
Spark.init();
//initializes the actual desktop web app
Application.launch(FrontEnd.class,args);
}
public static String getLinkPath() {return linkPath;}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)