Add reconnect mechanism.
This commit is contained in:
parent
1dab094d19
commit
4768d22168
@ -56,7 +56,15 @@ class ChessApp extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
floatingActionButton: const FloatingActionButton(
|
||||
onPressed: reconnect,
|
||||
child: Icon(Icons.connect_without_contact),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void reconnect() {
|
||||
ServerConnection.getInstance().reconnect();
|
||||
}
|
||||
|
@ -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'));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user