Я впервые во Flutter. Я пытаюсь подключиться к весеннему веб-сокету, который использует топт, но соединение не удается. Я использую Stomp_dart_client 0.3.3. Spring sever работает нормально. Я могу видеть сообщения в браузере.
Это моя реализация Spring:
Класс конфигурации Spring:
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/gs-guide-websocket").withSockJS();
}
Контроллер Spring:
@MessageMapping("/hello")
@SendTo("/topic/greetings")
public Greeting greeting(HelloMessage message) throws Exception {
Thread.sleep(1000); // simulated delay
return new Greeting("Hello, " + HtmlUtils.htmlEscape(message.getName()) + "!");
}
Реализация флаттера:
StompClient stompClient = StompClient(
config: StompConfig(
url: 'ws://10.0.2.2:7000',
onConnect:(ss, dd)=> ss.subscribe (
destination: '/topic/greetings/gs-guide-websocket',
callback: (StompFrame frame) {
print(frame.body);
},
),
onWebSocketError: (dynamic error) => print(error.toString()),
onStompError: (d) => print("stomp error"),
onDisconnect: (d)=> print("disconnect"),
));
stompClient.activate();
stompClient.subscribe (
destination: '/topic/greetings',
callback: (StompFrame frame) {
print(frame.body);
List<dynamic> result = json.decode(frame.body);
return result;
},
);
это ошибка:
E/flutter (30825): [ERROR:flutter/shell/common/shell.cc(213)] Dart Error: Unhandled exception:
E/flutter (30825): NoSuchMethodError: The method 'subscribe' was called on null.
E/flutter (30825): Receiver: null
E/flutter (30825): Tried calling: subscribe(callback: Closure: (StompFrame) => List<dynamic>, destination: "/topic/greetings", headers: null)
E/flutter (30825): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
E/flutter (30825): #1 StompClient.subscribe (package:stomp_dart_client/stomp.dart:74:21)
E/flutter (30825): #2 _MyHomePageState._receivedMessage (package:tutorial_projecect/main.dart:154:16)
E/flutter (30825): #3 _MyHomePageState.build (package:tutorial_projecect/main.dart:90:41)
E/flutter (30825): #4 StatefulElement.build (package:flutter/src/widgets/framework.dart:4619:28)
E/flutter (30825): #5 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4502:15)
E/flutter (30825): #6 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4675:11)
E/flutter (30825): #7 Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
E/flutter (30825): #8 StatefulElement.update (package:flutter/src/widgets/framework.dart:4707:5)
E/flutter (30825): #9 Element.updateChild (package:flutter/src/widgets/framework.dart:3201:15)
E/flutter (30825): #10 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5837:14)
E/flutter (30825): #11 Element.updateChild (package:flutter/src/widgets/framework.dart:3201:15)
E/flutter (30825): #12 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
E/flutter (30825): #13 Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
E/flutter (30825): #14 StatelessElement.update (package:flutter/src/widgets/framework.dart:4583:5)
E/flutter (30825): #15 Element.updateChild (package:flutter/src/widgets/framework.dart:3201:15)
E/flutter (30825): #16 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5837:14)
E/flutter (30825): #17 Element.updateChild (package:flutter/src/widgets/framework.dart:3201:15)
E/flutter (30825): #18 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5837:14)
E/flutter (30825): #19 Element.updateChild (package:flutter/src/widgets/framework.dart:3201:15)
E/flutter (30825): #20 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
E/flutter (30825): #21 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4675:11)
E/flutter (30825): #22 Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
E/flutter (30825): #23 StatefulElement.update (package:flutter/src/widgets/framework.dart:4707:5)
E/flutter (30825): #24 Element.updateChild (package:flutter/src/widgets/framework.dart:3201:15)
E/flutter (30825): #25 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5837:14)
E/flutter (30825): #26 Element.updateChild (package:flutter/src/widgets/framework.dart:3201:15)
E/flutter (30825): #27 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5837:14)
E/flutter (30825): #28 Element.updateChild (package:flutter/src/widgets/framework.dart:3201:15)
E/flutter (30825): #29 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
E/flutter (30825): #30 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4675:11)
E/flutter (30825): #31 Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
E/flutter (30825): #32 StatefulElement.update (package:flutter/src/widgets/framework.dart:4707:5)
E/flutter (30825): #33 Element.updateChild (package:flutter/src/widgets/framework.dart:3201:15)
E/flutter (30825): #34 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
E/flutter (30825): #35 Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
E/flutter (30825): #36 StatelessElement.update (package:flutter/src/widgets/framework.dart:4583:5)
E/flutter (30825): #37 Element.updateChild (package:flutter/src/widgets/framework.dart:3201:15)
E/flutter (30825): #38 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
E/flutter (30825): #39 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4675:11)
E/flutter (30825): #40 Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
E/flutter (30825): #41 StatefulElement.update (package:flutter/src/widgets/framework.dart:4707:5)
E/flutter (30825): #42 Element.updateChild (package:flutter/src/widgets/framework.dart:3201:15)
E/flutter (30825): #43 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5837:14)
E/flutter (30825): #44 Element.updateCh