没有 JEE/应用服务器的独立 WebSocket 服务器 [英] Standalone WebSocket server without JEE/application server

查看:45
本文介绍了没有 JEE/应用服务器的独立 WebSocket 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 Java SE 中实现一个相当简单的 WebSocket 服务器.它需要做的就是接受连接并存储相应的会话,然后在触发某个事件时向所有连接的客户端发送一条消息.

I need to implement a fairly simple WebSocket server in Java SE. All it needs to do is accept connections and store the respective sessions, then send a message to all connected client whenever a certain event is fired.

我找不到有关如何在常规 Java SE 中执行此操作的单个教程.所有这些都需要使用 Maven 运行,或者将其部署为 WAR——这对于这个项目来说都是不可能的.我需要将它作为 Java SE 桌面应用运行.

I cannot find a single tutorial for how to do this in regular Java SE. All of them require running with Maven, or deploying it as a WAR - which are all out of the question for this project. I need to run this as a Java SE desktop app.

我发现的教程展示了如何使用诸如 @OnOpen@OnMessage@OnClose 之类的注释来实现端点.但是,他们都没有解释如何实际初始化服务器.我还需要能够为传入连接指定不同的端口号.

The tutorials I have found show how to implement an endpoint using annotations like @OnOpen, @OnMessage, and @OnClose. However, none of them explain how to actually initialize the server. I also need to be able to specify a different port number for incoming connections.

我错过了什么吗?我知道人们已经使用 WebSocket 制作了聊天应用程序,这真的不需要 Web 应用程序服务器.我也没有使用 Maven,为了简单起见,我更愿意保持这种方式.

Am I missing something? I know people have made chat apps using WebSocket, and that really should not require a web application server. I am not using Maven either, and would prefer to keep it that way for simplicity's sake.

推荐答案

https://github.com/TooTallNate/Java-WebSocket 是 Java SE 中完整的 WebSockets 服务器和客户端实现,不需要企业/网络应用服务器.

https://github.com/TooTallNate/Java-WebSocket is a full WebSockets server and client implementation in Java SE, no enterprise/web app server needed.

这篇关于没有 JEE/应用服务器的独立 WebSocket 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆