【问题标题】:stomp_dart_client not connecting to serverstomp_dart_client 未连接到服务器
【发布时间】:2021-06-17 18:39:05
【问题描述】:

尝试在 Flutter 应用中设置与我的 Spring Boot 服务器的连接

final socketUrl = 'https://10.0.0.6:8443/notifications';
if (stompClient == null) {
      stompClient = StompClient(
          config: StompConfig.SockJS(
            url: socketUrl,
            onConnect: onConnect,
            onWebSocketError: (dynamic error) => print(error.toString()),
          ));

      print(stompClient.config.url);

      stompClient.activate();
    }

但永远不会调用 onConnect 函数,我也没有收到任何错误消息。我尝试将 url 更改为 wss://10.0.0.6:8443/notifications 并以相同的结果删除 SockJs。还尝试连接到 wss://echo.websocket.org 没有任何成功。

Web 服务器配置如下,并且具有有效证书

@Configuration
@EnableWebSocketMessageBroker
public class webSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

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

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/notifications");
        registry.addEndpoint("/notifications").withSockJS();
    }
}

从同一服务器上的 JS Web 应用调用套接字工作正常。

我尝试过其他颤振库(Stomp、Socket_IO、WebSocketChannel)来连接,但没有任何成功。我在配置中缺少什么吗?

【问题讨论】:

    标签: spring-boot flutter sockets websocket stomp


    【解决方案1】:

    您可能在使用 CORS 时遇到了问题。请只尝试这一行:

    registry.addEndpoint("/notifications").setAllowedOrigins("*").withSockJS();
    

    同时保留客户在此处发布的内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-09
      相关资源
      最近更新 更多