【发布时间】: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