GlassFish、Java、Grizzly、WebSockets - 如何开始?

发布于 2024-12-07 01:25:48 字数 230 浏览 3 评论 0原文

我需要将一些消息推送到我的 Java Web 应用程序的客户端。在阅读了有关该主题的一些内容后,我决定使用 websockets 作为一项新兴的、有前途的技术,并使用 GlassFish 作为服务器。然而,我发现的所有示例要么非常复杂,要么已经过时,并且无法使用 Grizzly 2 进行编译。

是否有一个非常简单的示例,只需几行代码即可将“hello,world”之类的内容推送给客户端?

提前致谢, 蒂莫菲。

I am faced with the necessity to push some messages to the clients of my web-application in Java. After some reading up on the subject, i decided to use websockets as an emerging and a promicing technology, and to use GlassFish as the server. However, all the examples i find are either quite complicated or outdated and do not compile with Grizzly 2.

Is there a really simple example with just a few lines of code that would push something like "hello, world" to the client?

Thanks in advance,
Timofey.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无法回应 2024-12-14 01:25:48

我知道你的意思。我一直在努力回复。您可能还对此处的 websockets 评论感兴趣。请阅读这些回复。他们可能会帮助您入门。建议演示中当前可下载的 javascript 代码旨在为测试提供一些灵活性和良好的功能 - 尽管如果您下载它并查看 WSTest.htm,它实际上并不那么复杂。可能正是您正在寻找的。然后也许我们可以聚在一起和灰熊一起解决问题。

更新:当我自己处理 grizzly 时,我在 glassfish 管理控制台的快速入门中发现,有一个 hello 示例,非常容易设置和运行。您会在那里找到说明。示例目录还包含一个名为:websocket-mozilla 的 war 文件;所以我猜它应该使用 websockets。熟悉jsp的人应该查看源代码。我只能看到它正在使用 http 会话。根本没有提到 websocket。这很像 hello 示例。

I know what you mean. I've been working on a response to this. You might also be interesting in beginning with websockets comment here. Please read those responses. They might help get you started. The current downloadable javascript code from the suggested demo is intended to provide some flexibility and nice features for testing - although if you download it and look into WSTest.htm, it's really not so complicated. Might be just what you're looking for. Then maybe we can all get together and work things out with grizzly.

UPDATE: As I work through grizzly myself, I found on the Quick Start in the glassfish admin console, there's a hello sample that's pretty easy to set up and run. You'll find instructions there. The sample directory also contains a war file named: websocket-mozilla; so I guess its supposed to use websockets. Someone who's familiar with jsp should review the source code. All I can see is that it's using an http session. No mention of a websocket at all. It's a lot like the hello sample.

左岸枫 2024-12-14 01:25:48

我在 GlassFish 上使用 CometD 实现。它有不同的传输协议,包括 Websockets(尽管他们还不推荐)。
请参阅我对另一个相关问题的回答

I use CometD implementation on GlassFish. It has different transport protocols including Websockets (although they don't recommend it yet).
See my answer to another related question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文