搜尋套件、儲存庫與 APP 分類

套件詳情v0.2.2

websocket_manager

適用於 Android 與 iOS 的 Flutter 插件,支援 WebSocket 連接

近 30 天下載
49
喜歡數
44
Pub 分數
40

安裝套件

flutter pub add websocket_manager

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個專為 Android 和 iOS 設計的 Flutter 插件,可實現無縫的 WebSocket 連接。它提供了一種可靠且高效的方式,用於在應用程式和伺服器之間保持即時通訊,支援雙向資料傳輸。該套件簡化了連接管理,包括自動重連和訊息處理,非常適合即時更新、聊天應用和即時通知。此套件以簡單性和效能為設計重點,可順利整合至 Flutter 專案中。

適用情境

  • 即時聊天應用
  • 即時資料流
  • 推送通知系統
  • 物聯網設備通訊
  • 在線遊戲功能

主要特色

  • 斷開連接後自動重連
  • 雙向訊息交換
  • 連接管理的簡單API
  • 對 JSON 和二進制訊息的支援
  • 內建錯誤處理

適合對象

  • 開發即時應用的開發者
  • 需要持久伺服器連接的應用程式
  • 需要低延遲通訊的項目

使用建議

  • 僅限 Android 和 iOS 平台
  • 無內建加密(需外部設定)
  • 依賴穩定的網路連接

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。


NOTE: This repository is no longer maintained by ENGAPP. It was moved to be maintained by Kunlatek on the following link: https://github.com/kunlatek/flutter_websocket_manager_plugin

Any issue regarding this plugin should be reported there.


Websocket Manager

A Flutter plugin for Android and iOS supports websockets. This plugin is based on two different native libraries Starscream for iOS and okHttp for Android.

This plugin was created due to our necessity to maintain a WebSocket connection active in background while Flutter's WebSocket from cookbook doesn't keep alive while screen is locked or the application was in background.

Introduction

Websocket Manager doesn't manipulate websockets in Dart codes directly, instead, the plugin uses Platform Channel to expose Dart APIs that Flutter application can use to communicate with two very powerful websocket native libraries. Because of that, all credits belong to these libraries.

How to install

Android

You only need this configuration if your server doesn't have SSL/TLS

Since Android P http is blocked by default and there are many ways to configure. One way to configure is explicitly saying that you accept clear text for some host.

  • Create res/xml/network_security_config.xml with content:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">your_domain</domain>
    </domain-config>
</network-security-config>
  • Point to this file from your manifest (for bonus points add it only for the test manifest):
<application
    android:networkSecurityConfig="@xml/network_security_config"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
    <activity android:name=" (...)
</application>
iOS

Doesn't require any configuration

Example

int messageNum = 0;
// Configure WebSocket url
final socket = WebsocketManager('wss://echo.websocket.org');
// Listen to close message
socket.onClose((dynamic message) {
    print('close');
});
// Listen to server messages
socket.onMessage((dynamic message) {
    print('recv: $message');
    if messageNum == 10 {
        socket.close();
    } else {
        messageNum += 1;
        final String msg = '$messageNum: ${DateTime.now()}';
        print('send: $msg');
        socket.send(msg);
    }
});
// Connect to server
socket.connect();

Credits

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。