Рамка WebSocket была отправлена ​​с непризнанным оптовым кодом [7]] Angular | Весенний ботинокJAVA

Программисты JAVA общаются здесь
Anonymous
Рамка WebSocket была отправлена ​​с непризнанным оптовым кодом [7]] Angular | Весенний ботинок

Сообщение Anonymous »

Frame Websocket с нераспознанным OpCode [7] при подключении от Angular к Spring Boot Websocket Server < /h1>
Я пытаюсь подключить угловое приложение к серверу Spring Boot Websocket, но я сталкиваюсь с ошибкой со следующим сообщением: < /p>

Код: Выделить всё

A WebSocket frame was sent with an unrecognised opCode of [7]
< /code>
Вот конфигурация Spring Boot Websocket, которую я использую: < /p>
@Configuration
@EnableWebSocketMessageBroker
public class WebsocketConfig implements WebSocketMessageBrokerConfigurer {

@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/chess-websocket").setAllowedOrigins("http://localhost:4200").withSockJS();
}

}
< /code>
И это угловой код, который я использую для подключения к Websocket: < /p>
import { Component, OnInit } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { Client } from '@stomp/stompjs';
import SockJS from 'sockjs-client';

@Component({
selector: 'app-root',
standalone: true,
imports: [RouterOutlet],
templateUrl: './app.component.html',
styleUrl: './app.component.css',
})
export class AppComponent implements OnInit {
title = 'client';

ngOnInit(): void {
const socket = new SockJS('http://localhost:8080/chess-websocket');
const stompClient = new Client({
webSocketFactory: () => socket,
debug: (msg) => console.log(msg),
onConnect: () => console.log('Connected'),
onStompError: (frame) => console.error('STOMP Error:', frame),
});
stompClient.activate();
}
}
зависимости в package.json :

Код: Выделить всё

"dependencies": {
"@angular/animations": "^18.2.0",
"@angular/common": "^18.2.0",
"@angular/compiler": "^18.2.0",
"@angular/core": "^18.2.0",
"@angular/forms": "^18.2.0",
"@angular/platform-browser": "^18.2.0",
"@angular/platform-browser-dynamic": "^18.2.0",
"@angular/router": "^18.2.0",
"@stomp/stompjs": "^7.0.0",
"rxjs": "~7.8.0",
"sockjs-client": "^1.6.1",
"tslib": "^2.3.0",
"zone.js": "~0.14.10"
}

зависимости в pom.xml :

Код: Выделить всё

    

org.springframework.boot
spring-boot-starter-websocket


org.springframework.boot
spring-boot-starter



org.springframework.boot
spring-boot-starter-test
test


< /code>
Это, по-видимому, связано с кадром WebSocket, отправленной со стороны клиента. Я пытался использовать Sockjs 
с библиотекой @Stomp/Stompjs , но ошибка сохраняется. Любая помощь будет очень признателен! Настройки.
[*] Обновление всех соответствующих зависимостей, включая @stomp/stompjs и sockjs-client .


Подробнее здесь: https://stackoverflow.com/questions/792 ... lar-spring

Вернуться в «JAVA»