stop method

Future<void> stop()

Stops the WebSocket server and disconnects all clients.

This method closes all active WebSocket connections with connected clients and then shuts down the WebSocket server.

Implementation

Future<void> stop() async {
  for (var client in _clients) {
    await client.close(); // Close each client connection.
  }
  _clients.clear(); // Clear the list of clients.
  await _server?.close(force: true); // Close the server.
  debugPrint('WebSocket server stopped.');
}