28 lines
577 B
Dart
28 lines
577 B
Dart
|
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++;
|
||
|
}
|
||
|
}
|