Skip to content

Instantly share code, notes, and snippets.

@felixblaschke
Created February 5, 2022 11:27
Show Gist options
  • Save felixblaschke/8aa0cc5b38b714240a6b1739a0aefc12 to your computer and use it in GitHub Desktop.
Save felixblaschke/8aa0cc5b38b714240a6b1739a0aefc12 to your computer and use it in GitHub Desktop.
import 'package:web_socket_channel/web_socket_channel.dart';
class SomeClass {
// Contains message history
final _messages = <String>[];
late final WebSocketChannel _channel;
void createConnection() {
// Connect to web socket
_channel = WebSocketChannel.connect(Uri.parse('ws://localhost:8080/ws'));
// Listen for incoming messages
_channel.stream.listen(
(message) => _messages.add(message),
);
// Send messages to the server
_channel.sink.add('Hello fellows!');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment