Add class that handles server connections via web sockets.

This commit is contained in:
Marco 2022-11-13 14:25:47 +01:00
parent 05980a6b63
commit 76e141619b

View File

@ -0,0 +1,27 @@
import 'package:web_socket_channel/web_socket_channel.dart';
class ServerConnection {
late WebSocketChannel channel;
late int counter = 0;
static final ServerConnection _instance = ServerConnection._internal();
ServerConnection._internal() {
channel = WebSocketChannel.connect(
Uri.parse('ws://localhost:8080'),
);
}
factory ServerConnection() {
return _instance;
}
factory ServerConnection.getInstance() {
return ServerConnection();
}
void send(String message) {
channel.sink.add('$message: $counter');
counter++;
}
}