diff --git a/lib/connection/ws_connection.dart b/lib/connection/ws_connection.dart new file mode 100644 index 0000000..2b3e3c0 --- /dev/null +++ b/lib/connection/ws_connection.dart @@ -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++; + } +}