无法连接到Spring AbstractWebSocketMessageBrokerConfigurer上的websocket

时间:2014-12-22 06:46:43

标签: spring websocket

请求

http://localhost:8080/chat/info

给出

{"entropy":1407128458,"origins":["*:*"],"cookie_needed":true,"websocket":true}

但是当我尝试使用websocket服务器时,它是未定义的

使用: 春季启动 嵌入式tomcat     @EnableWebSocketMessageBroker     ...

public void registerStompEndpoints(StompEndpointRegistry registry) {
    registry.addEndpoint("/chat").withSockJS();
}

issue explained in screenshot

1 个答案:

答案 0 :(得分:1)

您在服务器端启用SockJS但在客户端使用普通的WebSocket API,请改用sockjs client library。替换:

var socket = new WebSocket("ws://localhost:8080/chat");

使用:

var socket = new SockJS("http://localhost:8080/chat");