我在连接到 websocket 时的状态为 200,但这是一个错误?
2022-09-01 03:34:19
我的错误显示在浏览器的控制台中:
"WebSocket connection to 'ws://localhost:32768/DspClusterWebServices/myHandler' failed: Unexpected response code: 200"
我正在使用 和 .我的 WebSocketConfigurer 实现类如下所示:Spring Websockets 4.1.5
Tomcat 8.0.18
@Configuration
@Controller
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer
{
class MyHandler implements WebSocketHandler
{
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception
{
System.out.println("afterConntectionEstablished called");
}
...implements rest of functions with a System.out.println and false for supportsPartialMessages()
}
}
@Override registerWebSocketHandlers(WebSocketHandlerRegistry registry)
{
registry.addHandler(myHandler(), "myHandler").withSockJS();
}
@Bean
public WebSocketHandler myHandler()
{
return new MyHandler();
}
}
我的 testWebsocketClient.js 尝试使用此代码进行连接,但错误代码为 200:
websocket = new WebSocket("ws://localhost:8080/myApp/myHandler");
我不知道下一步该尝试什么。我以为这会导致 AfterConnectionEstablished(WebSocketSession session) 方法触发?代码200不是很好吗?