start method

Future<void> start()

Starts the proxy server. Binds to the configured IP and port, and listens for incoming connections. If the port is already in use, it will try the next port.

Implementation

Future<void> start() async {
  try {
    final InternetAddress internetAddress = InternetAddress(Config.ip);
    server = await ServerSocket.bind(internetAddress, Config.port);
    logD('Proxy server started ${server?.address.address}:${server?.port}');
    server?.listen(_handleConnection);
  } on SocketException catch (e) {
    logW('Proxy server Socket close: $e');
    // If the port is occupied (error code 98), increment port and retry.
    if (e.osError?.errorCode == 98) {
      Config.port = Config.port + 1;
      start();
    }
  }
}