diff --git a/lib/chessapp/chess_app.dart b/lib/chessapp/chess_app.dart index 782ea43..435afcc 100644 --- a/lib/chessapp/chess_app.dart +++ b/lib/chessapp/chess_app.dart @@ -56,7 +56,15 @@ class ChessApp extends StatelessWidget { ), ), ), + floatingActionButton: const FloatingActionButton( + onPressed: reconnect, + child: Icon(Icons.connect_without_contact), + ), ), ); } } + +void reconnect() { + ServerConnection.getInstance().reconnect(); +} diff --git a/lib/connection/ws_connection.dart b/lib/connection/ws_connection.dart index 2b3e3c0..ebe1715 100644 --- a/lib/connection/ws_connection.dart +++ b/lib/connection/ws_connection.dart @@ -7,6 +7,7 @@ class ServerConnection { static final ServerConnection _instance = ServerConnection._internal(); ServerConnection._internal() { + print("ServerConnection._interal constructor is called"); channel = WebSocketChannel.connect( Uri.parse('ws://localhost:8080'), ); @@ -21,7 +22,11 @@ class ServerConnection { } void send(String message) { - channel.sink.add('$message: $counter'); + channel.sink.add('$counter $message'); counter++; } + + void reconnect() { + channel = WebSocketChannel.connect(Uri.parse('ws://localhost:8080')); + } }