createConnection method

Future<void> createConnection()

Implementation

Future<void> createConnection() async {
  if (!isConnectionAvailable()) {
    //1. find secondary url for atsign from lookup library
    var secondaryUrl =
        await findSecondary(_currentAtSign, _rootDomain, _rootPort);
    if (secondaryUrl == null) {
      throw SecondaryNotFoundException('Secondary server not found');
    }
    var secondaryInfo = LookUpUtil.getSecondaryInfo(secondaryUrl);
    var host = secondaryInfo[0];
    var port = secondaryInfo[1];
    //2. create a connection to secondary server
    await createOutBoundConnection(host, port, _currentAtSign);
    //3. listen to server response
    messageListener = OutboundMessageListener(_connection);
    messageListener.listen();
  }
}