flutter_web_socket 1.0.5 copy "flutter_web_socket: ^1.0.5" to clipboard
flutter_web_socket: ^1.0.5 copied to clipboard

Flutter WebSocket Utils simplifies WebSocket communication in Flutter apps. Effortlessly integrate real-time data exchange and communication features.

example/lib/main.dart

import 'package:flutter_web_socket/flutter_web_socket.dart';

void main() {
  connectToWebSocket(
    socketUrl: 'wss://socketsbay.com/wss/v2/1/demo/',
  ).then((webSocket) {
    if (webSocket != null) {
      // WebSocket connection successful, you can now interact with the server
      webSocket.listen(
        (data) {
          print('Received message: $data');
        },
        onError: (error) {
          print('Error occurred: $error');
        },
        onDone: () {
          print('WebSocket connection closed');
        },
      );

      webSocket.add('Hello, Server!');

      // To close the WebSocket connection, you can use:
      // webSocket.close();
    } else {
      // WebSocket connection failed
      print('WebSocket connection failed.');
    }
  });
}
5
likes
160
pub points
80%
popularity

Publisher

verified publisheryasirali.link

Flutter WebSocket Utils simplifies WebSocket communication in Flutter apps. Effortlessly integrate real-time data exchange and communication features.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on flutter_web_socket