【发布时间】:2018-04-07 18:52:05
【问题描述】:
我已经按照this tutorial 构建了一个提供websockets 连接的 Spring Boot 应用程序,但是除了 Spring Boot 本身提供的客户端之外,我无法从其他客户端连接到这些 websocket。
complete directory in the GitHub repository that accompanies the tutorial 包含最终的 Spring Boot 代码。我从这个存储库中获取了index.html 和app.js 文件,并创建了另一个在Node.js 服务器上运行的客户端。之后,我将连接字符串替换为指向localhost:8080(Spring Boot 正在运行的地方)。然后我运行 Node.js 服务器并尝试使用 websockets,但它不起作用。
通过将.setAllowedOrigins("*") 添加到StompEndpointRegistry 注册表很容易解决第一个问题。通过这个配置,我设法连接到 websocket,但现在我再也没有从 socket 收到消息了。
我想知道我错过了什么......有人知道问题出在哪里吗?
提取的index.html 和app.js(重命名为index.js)文件,以及用于测试目的的the Node.js server can be found here。要运行它,只需安装依赖项 (npm install),然后发出 npm start。服务器将回复http://localhost:3000/。
【问题讨论】:
标签: spring spring-boot websocket cors stomp