简体   繁体   English

寻找JavaScript和Java之间的简单通信方式

[英]Looking for simple way of communication between JavaScript and Java

Intro: I want to develop simple multiplayer Five in row (Gomoku). 简介:我想开发简单的多人五人行(Gomoku)。 Front-end should be done using JavaScript, and back-end in Java. 前端应使用JavaScript进行,后端应使用Java。

Basically client and server should exchange pairs of integer numbers and game id. 基本上,客户端和服务器应该交换成对的整数和游戏ID。 It's easy to do on client side with WebSockets, but... 使用WebSocket在客户端很容易做到,但是...

Question: Is there simple way to process communication on server side, using Sockets and ServerSocket, without embedding Jetty or any other server? 问题:是否有简单的方法可以使用Sockets和ServerSocket在服务器端处理通信,而无需嵌入Jetty或任何其他服务器?

Since Front-end is javascript it might run in a web browser. 由于前端是javascript,因此可以在网络浏览器中运行。 To communicate with the server most likely using http, then embedding Jetty and using dwr is the simplest way IMO. 要最有可能使用http与服务器通信,然后嵌入Jetty并使用dwr是IMO最简单的方法。

如果您打算在Web项目上执行此操作,请查看DWR项目

WebSockets browser support is poor at the moment. 目前,WebSockets浏览器支持不佳。

If you're creating a Web application the mainstream solution for JS-Java communication is Ajax with some JS framework like jQuery or Dojo . 如果要创建Web应用程序,则JS-Java通信的主流解决方案是Ajax,它带有jQueryDojo之类的JS框架。 It will not require any libs on the server side (unlike DWR) and also you don't need to put any JS stuff on your server if you use CDN . 它不需要服务器端的任何库(与DWR不同),如果使用CDN,则不需要在服务器上放置任何JS东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM