Created
February 5, 2022 11:27
-
-
Save felixblaschke/8aa0cc5b38b714240a6b1739a0aefc12 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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