我遵循this tutorial构建了一个Spring Boot应用程序,该应用程序为websockets
连接提供服务,但是我无法连接到除Spring Boot本身提供的其他客户端的这些WebSocket。CORS和Spring Websocket
complete
directory in the GitHub repository that accompanies the tutorial包含最终的Spring启动代码。我从此存储库获取了index.html
和app.js
文件,并创建了另一个在Node.js服务器上运行的客户端。之后,我将连接字符串替换为指向localhost:8080
(其中Spring Boot正在运行)。然后我运行Node.js服务器并试图使用websockets,但它不起作用。
第一个问题很容易通过将.setAllowedOrigins("*")
添加到StompEndpointRegistry
注册表中解决。有了这个配置,我设法连接到websocket,但是现在我永远不会从套接字中获取消息。
我不知道我错过了什么......有人知道什么是问题吗?
提取的index.html
和app.js
(更名为index.js
)文件,以及the Node.js server can be found here用于测试目的。要运行它,只需安装依赖项(npm install
),然后发出npm start
。服务器将在http://localhost:3000/上进行响应。