服务器端 WebSockets 的最佳 Java 框架

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4003102/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 08:11:33  来源:igfitidea点击:

Best Java framework for server side WebSockets

javawebsocket

提问by boqapt

I want to create simple server having low load. The goal is to give a few javascript clients access to some functionality implemented in Java through WebSockets. I seek for best library to use for that - it should be simple, robust etc. Now I consider 3 alternatives - jWebSocket - jetty - netty What is the best? Or may be something else?

我想创建低负载的简单服务器。目标是让一些 javascript 客户端通过 WebSockets 访问一些在 Java 中实现的功能。我寻找最好的库来使用它 - 它应该简单,健壮等。现在我考虑 3 个替代方案 - jWebSocket - jetty - netty 什么是最好的?或者可能是别的什么?

Thanks in advance

提前致谢

采纳答案by user502448

jWebSocket now includes the Jetty 8.0 engine including SSL and includes many nice-to-haves on top of it. It provides cross-browser and cross-platform compatible clients even more mobile apps e.g. under Android, Symbian and BlackBerry. The server can easily be extended with plug-in and already includes lots of them (e.g. for Authentication/Autorization, JDBC, SMTP, XMPP/Jabber, RPC, Twitter, Filesharing, Chat etc.). Just check it out... http://jwebsocket.org. Looking forward to your feedback.

jWebSocket 现在包含 Jetty 8.0 引擎,包括 SSL,并在其之上包含许多不错的东西。它提供跨浏览器和跨平台兼容的客户端,甚至更多的移动应用程序,例如在 Android、Symbian 和 BlackBerry 下。服务器可以很容易地通过插件进行扩展,并且已经包含了很多插件(例如,用于身份验证/自动化、JDBC、SMTP、XMPP/Jabber、RPC、Twitter、文件共享、聊天等)。只需检查一下... http://jwebsocket.org。期待您的反馈意见。

Regards Alex

问候亚历克斯

回答by Bozho

Take a look at Atmosphere. Here is an articleabout websocket and atmosphere.

看看大气这是一篇关于 websocket 和氛围的文章

回答by Peter Knego

I'd go with proven Java servlet servers: Jetty or Resin. The have both been extended to handle WebSockets:

我会选择经过验证的 Java servlet 服务器:Jetty 或 Resin。两者都被扩展为处理 WebSockets:

Jetty WebSockets

码头网络套接字

Resin WebSockets

树脂网络套接字

My personal choice would be Jetty, as it's very simple to use and I've been using it as embedded server in several projects.

我个人的选择是 Jetty,因为它使用起来非常简单,而且我已经在几个项目中将它用作嵌入式服务器。

There are also some new kids on the block like Atmosphereand jWebSocket, but for servers I prefer to go with a proven solution. Jetty and Resin are also generic Servlet servers, so you can go with one product for all your serving needs.

还有一些新的孩子,比如AtmospherejWebSocket,但对于服务器,我更喜欢使用经过验证的解决方案。Jetty 和 Resin 也是通用的 Servlet 服务器,因此您可以使用一种产品来满足您的所有服务需求。

回答by jfarcand

FYI, Atmosphere run on top of Resin, GlassFish and Jetty. Atmosphere free you from being stuck with one server by giving you Websocket portability amongst Websocket server. It also offer a client library that can be select the best transport in case websocket isn't supported by the browser. So you can't compare Atmosphere with Jetty or Rsin

仅供参考,Atmosphere 运行在 Resin、GlassFish 和 Jetty 之上。通过为您提供 Websocket 服务器之间的 Websocket 可移植性,氛围使您免于被一台服务器困住。它还提供了一个客户端库,可以在浏览器不支持 websocket 的情况下选择最佳传输。所以你不能将 Atmosphere 与 Jetty 或 Rsin 进行比较

回答by Roger F. Gay

Follow my blog. I'll be ready for release sometime in the not too far off future. Light-weight has been emphasized through the whole thing - but it's also fast. I don't know yet how well it will ramp up to higher loads. But I've been running the demo for a while now with relatively low load and what I have has been working well. (I'll test heavier loads later and make sure that it can be ramped up.)

关注我的博客。我将准备好在不久的将来某个时候发布。整个过程都强调轻量级 - 但它也很快。我还不知道它会在多大程度上提升到更高的负载。但是我已经运行了一段时间的演示,负载相对较低,而且我一直运行良好。(稍后我将测试更重的负载并确保它可以增加。)

http://highlevellogic.blogspot.com/2011/09/websocket-server-demonstration_26.html

http://highlevellogic.blogspot.com/2011/09/websocket-server-demonstration_26.html

回答by David d C e Freitas

The PlayFramework!is the other very good option.

游戏框架!是另一个非常好的选择。

回答by colin moock

If you are looking for infrastructure around message management, user grouping ("rooms"), and data synchronization ("shared variables"), you might want to consider Union Platform:

如果您正在寻找围绕消息管理、用户分组(“房间”)和数据同步(“共享变量”)的基础设施,您可能需要考虑联合平台:

http://www.unionplatform.com

http://www.unionplatform.com

[Full disclosure: I am one of the co-creators of Union]

[全面披露:我是Union的共同创建者之一]

回答by websocket

Why don't you just write your application on an open standard like JMS, and let the clients sit on the JMS bus as message clients? The whole point of websockets is to bring any native TCP protocol directly to the client instead of converting it from your back end to http request/response.

为什么不直接在 JMS 等开放标准上编写应用程序,让客户端作为消息客户端坐在 JMS 总线上?websockets 的全部意义在于将任何原生 TCP 协议直接带到客户端,而不是将其从后端转换为 http 请求/响应。

Your back end services would talk to a JMS broker like ActiveMQ, and your clients speak AMQP in the browser via a Javascript API that looks just like the JMS API in Java. All you need for that is a websocket gateway, for example Kaazing has such a gateway, all it does is route your JMS TCP traffic out to the web clients over websockets. They also provide fan-out so that you don't overload your JMS bus, i.e. you just use a handful of connections to the broker to offload a million browser client connections.

您的后端服务将与像 ActiveMQ 这样的 JMS 代理通信,而您的客户端通过 Javascript API 在浏览器中使用 AMQP,看起来就像 Java 中的 JMS API。你所需要的只是一个 websocket 网关,例如 Kaazing 有一个这样的网关,它所做的就是通过 websockets 将你的 JMS TCP 流量路由到 web 客户端。它们还提供扇出,这样您就不会使 JMS 总线过载,即您只需使用少量连接到代理即可卸载一百万个浏览器客户端连接。

The bottom line is that you don't need to tie yourself to any specific platform. Stick with standards, that way you have 100% freedom to swap out components as your environment changes.

最重要的是,您不需要将自己绑定到任何特定平台。坚持标准,这样您就可以 100% 自由地在环境变化时更换组件。

回答by voitec

Maybe you should try Bristleback Server? Using Bristleback, you may choose from several WebSockets engines, like Jetty, Netty and Tomcat. You can have standalone server as well as web application that uses WebSockets (Jetty and Tomcat 7). Bristleback uses Spring Framework. If you have worked with web frameworks like Struts, Stripes or Play!, it will be very easy for you to start. Of course, Bristleback has its own JavaScript client library for even easier development.

也许你应该试试Bristleback Server?使用 Bristleback,您可以从多个 WebSockets 引擎中进行选择,例如 Jetty、Netty 和 Tomcat。您可以拥有独立服务器以及使用 WebSockets(Jetty 和 Tomcat 7)的 Web 应用程序。Bristleback 使用 Spring 框架。如果您使用过 Struts、Stripes 或 Play! 等 Web 框架,那么您将很容易上手。当然,Bristleback 有自己的 JavaScript 客户端库,可以更轻松地进行开发。

Full disclosure: I am one of the co-creators of Bristleback Server.

完全披露:我是 Bristleback Server 的共同创建者之一。

回答by Andrejs

I would also add vert.xto the list. It can server Websockets and SockJS (websocket emulation when the browser doesn't support them).

我还会将vert.x添加到列表中。它可以为 Websockets 和 SockJS(当浏览器不支持它们时的 websocket 模拟)提供服务。

Update:
Undertow http://undertow.ioalso supports websockets.

更新:
Undertow http://undertow.io也支持 websockets。