Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

279
Views
Obtengo un estado 200 cuando me conecto al websocket, pero ¿es un error?

Mi error aparece en la consola de mi navegador:

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

Estoy usando Spring Websockets 4.1.5 y Tomcat 8.0.18 . Mi clase de implementación WebSocketConfigurer se ve así:

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

Mi testWebsocketClient.js intenta conectarse con este código, pero tiene un código de error de 200:

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

No puedo averiguar qué probar a continuación. Pensé que esto haría que se disparara el método afterConnectionEstablished (WebSocketSession session). ¿No es bueno el código 200?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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

Después de agregar /websocket (a su URL), le dará el error

No se pudo analizar el valor del encabezado de origen [null]

;), que a su vez te llevará a ese enlace .

Tendrá que agregar .setAllowedOrigins("*") a su método addHandler() , ¡y finalmente podría funcionar!

over 4 years ago · Santiago Trujillo Report

0

Como mi otra respuesta:[ https://stackoverflow.com/a/53272666/2930417][1]

Yo uso springboot 2 +STOMP。

elimine .withSockJS() , entonces todo está bien.

No sé la razón, pero funciona para mí.

over 4 years ago · Santiago Trujillo Report

0

Echa un vistazo a la especificación . El servidor debe responder con 101 para señalar el cambio de protocolo de http a ws .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!