web_socket_cli 0.0.11 copy "web_socket_cli: ^0.0.11" to clipboard
web_socket_cli: ^0.0.11 copied to clipboard

A cross-platform WebSocket client with support for headers and followRedirects.

Web_Socket_Cli Package #

A cross-platform WebSocket client for Flutter and Dart applications. Supports headers, redirects, and works on web, iOS, and Android.

Features #

  • Cross-platform support (web, iOS, Android).
  • Custom headers for WebSocket connections.
  • Redirect handling (on supported platforms).

Installation #

Add the following to your pubspec.yaml:

dependencies:
  web_socket_cli: ^0.0.11

Run flutter pub get or dart pub get to install the package.

Usage #

import 'package:web_socket_cli/web_socket_cli.dart';
import 'dart:typed_data';

void main() {
  final client = WebSocketClient('wss://example.com/ws');

  client.messages.listen((message) {
    if (message is Uint8List) {
      // Handle binary data
      print('Received binary message: ${message.length} bytes');
      // Decode the binary data at the application level
      decodeBinaryMessage(message);
    } else if (message is String) {
      // Handle text messages
      print('Received text message: $message');
    }
  });

  // Sending binary data
  final binaryData = Uint8List.fromList([1, 2, 3, 4, 5]);
  client.send(binaryData);

  // Sending text data
  client.send('Hello, WebSocket!');
}

void decodeBinaryMessage(Uint8List data) {
  // Your custom binary data decoding logic
  print('Decoding binary message: $data');
}

0
likes
130
points
204
downloads

Publisher

unverified uploader

Weekly Downloads

A cross-platform WebSocket client with support for headers and followRedirects.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, universal_io

More

Packages that depend on web_socket_cli