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

Flutter WebSocket Utils is a powerful package that simplifies WebSocket communication in Flutter applications. It provides a convenient API for establishing WebSocket connections, sending and receivin [...]

Connecting to a WebSocket #

To connect to a WebSocket server, use the connectToWebSocket method provided by the web_socket_utils package. Provide the WebSocket server URL as a parameter to establish the connection.

web_socket_utils #

flutter_web_socket is a Dart package that provides a utility method for establishing WebSocket connections and interacting with WebSocket servers.

Usage #

To use this package, follow these steps:

  1. Add the flutter_web_socket dependency to your pubspec.yaml file:

    dependencies:
      flutter_web_socket: ^1.0.2
    
  2. Import the package in your Dart file:

    import 'package:web_socket_utils/web_socket_utils.dart';
    
  3. Establish a WebSocket connection using the connectToWebSocket method. Pass the desired WebSocket server URL as a parameter:

    WebSocket webSocket = await connectToWebSocket('ws://echo.websocket.org');
       
    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
0
pub points
80%
popularity

Publisher

verified publisheryasirali.link

Flutter WebSocket Utils is a powerful package that simplifies WebSocket communication in Flutter applications. It provides a convenient API for establishing WebSocket connections, sending and receiving messages, and handling connection events. With Flutter WebSocket Utils, developers can effortlessly integrate real-time data exchange and communication features into their Flutter apps.

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on flutter_web_socket