2017-03-28 114 views
0

我想订阅一个特定的频道在春季网络套接字,但同时指向一个URL使用SockJs我得到以下错误WebSocket connection to 'ws://localhost:8080/Spring/rest/user/chat/045/jmfz3b3j/websocket' failed: Error during WebSocket handshake: Unexpected response code: 200请帮我避免这一点。 这是我订阅的客户端代码。如何解决“失败:WebSocket握手过程中的错误:意外的响应代码:200”在春季websockets?

的index.jsp

var stompClient =null; 
 
     function subscribe(){ 
 
var socket = new SockJS('/Spring/rest/user/chat'); 
 
stompClient = Stomp.over(socket); 
 
stompClient.connect({}, function(frame) { 
 
    console.log('Connected: ' + frame); 
 
    stompClient.subscribe('/topic/messages', function(test) { 
 
     \t alert("in call back function");}); 
 
}); 
 
}

+0

看起来像服务器与客户端不匹配的端点。发布服务器端的代码片段以供审阅。 – Kane

+0

@Kane请检查以下代码段。 –

回答

0

@Kane这是spring-servlet.xml

<websocket:message-broker application-destination-prefix="/app" > 
    <websocket:stomp-endpoint path="/chat" allowed-origins="*"> 
     <websocket:sockjs /> 
    </websocket:stomp-endpoint> 
    <websocket:simple-broker prefix="/topic"/> 
</websocket:message-broker> 

我WebSocket的配置,这是我controller代码

@Controller 
@RequestMapping("user") 
public class OptnCptController{ 
    @MessageMapping("topic/messages") 
    public String getMsg(String s) 
    { 
     return s; 
    } 
} 
相关问题