Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I get a status 200 when connecting to the websocket, but it is an error?

My error shows up in the console of my browser:

"WebSocket connection to 'ws://localhost:32768/DspClusterWebServices/myHandler' failed: Unexpected response code: 200"

I am using Spring Websockets 4.1.5 and Tomcat 8.0.18. My WebSocketConfigurer implementation class looks like:

@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();    } } 

My testWebsocketClient.js tries to connect with this code, but has a error code of 200:

websocket = new WebSocket("ws://localhost:8080/myApp/myHandler"); 

I cannot figure out what to try next. I thought that this would cause the afterConnectionEstablished(WebSocketSession session) method to fire? Isn't code 200 good?

like image 955
smuggledPancakes Avatar asked Apr 23 '15 16:04

smuggledPancakes


People also ask

What causes WebSocket error?

The error event is fired when a connection with a WebSocket has been closed due to an error (some data couldn't be sent for example).

What does WebSocket error mean?

A WebSocket error indicates a problem with the connection between your Ledger device and the Ledger Live application. Some users have reported facing this error message by using Ledger Live in places with restricted internet access.

How do I check my WebSocket connection status?

In the search field, enter websocket . From the search results, click WebSocket Connection Status.


1 Answers

Please check http://procbits.com/connecting-to-a-sockjs-server-from-native-html5-websocket!

After you append /websocket (to your URL), it will give you the error

Failed to parse Origin header value [null]

;) , which then will in turn lead you to that link.

You'll have to add .setAllowedOrigins("*") to your addHandler() method, and then it could finally work!

like image 53
xerx593 Avatar answered Sep 24 '22 19:09

xerx593