unable to use https connection in flutter's serverpod

163 views Asked by At

We have setup a client connection to the server using serverpod. we setup ssl on the server, and we're able to use https:// connections when making rest calls to the server, but for our websocket connection, we are unable to switch it over to https://

When we do we get an error stating the client cannot connect to the server, but the error says its still trying to use HTTP:

I/flutter ( 6431): SocketException: HTTP connection timed out after 0:00:20.000000, host: <ip>, port: 8080
I/flutter ( 6431): recreating client...

Here's our SubscriptionService Object which sets up a connection to the backend called client:

import 'dart:async';
import 'package:serverpod_client/serverpod_client.dart';

class SubscriptionService {

  static const String url = 'http://<ip>:8080'; // works
  //static const String url = 'https://<ip>:8080'; // does not work

  final server.Client client;
  late server.ConnectivityMonitor monitor;
  bool isConnected = false;
  late StreamingConnectionHandler connectionHandler;
  List<StreamSubscription<dynamic>> listeners = <StreamSubscription<dynamic>>[];

  SubscriptionService() : client = server.Client('$url/');

  Future<void> setupClient(server.ConnectivityMonitor givenMonitor) async {
    monitor = givenMonitor;
    client.connectivityMonitor = givenMonitor;
    connectionHandler = StreamingConnectionHandler(
      client: client,
      listener: (StreamingConnectionHandlerState connectionState) {
        print('connection state: ${connectionState.status.name}');
      },
    );
    print('connecting!');
    try {
      connectionHandler.connect();
    } catch (e) {
      print(e);
    }
    await setupListeners();
  }
  ...
}

Serverpod documentation seems to have changed since we implemented this solution, I think this corresponds to it: https://docs.serverpod.dev/concepts/streams but that describes WebSockets where, we are specifying StreamingConnectionHandler so I'm not sure if it's the same.

0

There are 0 answers