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

套件詳情v1.0.1

socket_io

JS/Node 庫 Socket.io 的移植版本。可實現跨平台的即時、雙向及基於事件的通訊。

AndroidiOSmacOSWindowsLinux
近 30 天下載
1550
喜歡數
134
Pub 分數
130

安裝套件

flutter pub add socket_io

套件介紹

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

Socket.IO 是流行的 JavaScript/Node.js Socket.IO 庫的 Dart 版本,可在跨平台環境中實現即時、雙向和事件驅動的通訊。它支援 WebSocket 和備用傳輸方式,非常適合需要即時更新的應用程式,例如聊天應用、協作工具或即時儀表板。該套件與 Flutter 無縫整合,可在 Android、iOS、macOS、Windows 和 Linux 上提供一致的行為。它輕鬆實現事件發射、房間管理與連接處理。

適用情境

  • 即時聊天應用
  • 即時資料同步
  • 協作編輯工具
  • 物聯網裝置監控
  • 多人遊戲網路

主要特色

  • 跨平台 WebSocket 支持
  • 基於事件的通訊
  • 自動傳輸回退
  • 房間和命名空間管理
  • 用於發射和監聽的簡單 API

適合對象

  • 即時網路和行動應用程式
  • 需要即時更新的應用程式
  • 熟悉 Socket.IO 的開發人員
  • 需要低延遲通訊的項目

使用建議

  • 需要相容的伺服器(例如 Node.js Socket.IO)
  • 可能需要為防火牆進行額外設定
  • 性能取決於網路狀況
  • 未優化,不適用於高頻率、低延遲場景

原始 README

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

socket.io-dart

Port of awesome JavaScript Node.js library - Socket.io v2.0.1 - in Dart

Usage

import 'package:socket_io/socket_io.dart';

main() {
    var io = new Server();
    var nsp = io.of('/some');
    nsp.on('connection', (client) {
      print('connection /some');
      client.on('msg', (data) {
        print('data from /some => $data');
        client.emit('fromServer', "ok 2");
      });
    });
      io.on('connection', (client) {
        print('connection default namespace');
        client.on('msg', (data) {
          print('data from default => $data');
          client.emit('fromServer', "ok");
        });
      });
      io.listen(3000);
}
// JS client
var socket = io('http://localhost:3000');
socket.on('connect', function(){console.log('connect')});
socket.on('event', function(data){console.log(data)});
socket.on('disconnect', function(){console.log('disconnect')});
socket.on('fromServer', function(e){console.log(e)});
// Dart client
import 'package:socket_io_client/socket_io_client.dart' as IO;

IO.Socket socket = IO.io('http://localhost:3000');
socket.on('connect', (_) {
  print('connect');
  socket.emit('msg', 'test');
});
socket.on('event', (data) => print(data));
socket.on('disconnect', (_) => print('disconnect'));
socket.on('fromServer', (_) => print(_));

Multiplexing support

Same as Socket.IO, this project allows you to create several Namespaces, which will act as separate communication channels but will share the same underlying connection.

Room support

Within each Namespace, you can define arbitrary channels, called Rooms, that sockets can join and leave. You can then broadcast to any given room, reaching every socket that has joined it.

Transports support

Refers to engine.io

  • polling: XHR / JSONP polling transport.
  • websocket: WebSocket transport.

Adapters support

Notes to Contributors

Fork socket.io-dart

If you'd like to contribute back to the core, you can fork this repository and send us a pull request, when it is ready.

If you are new to Git or GitHub, please read this guide first.

Who Uses

  • Quire - a simple, collaborative, multi-level task management tool.
  • KEIKAI - a web spreadsheet for Big Data.

Socket.io Dart Client

Contributors

  • Thanks @felangel for https://github.com/rikulo/socket.io-dart/issues/7
  • Thanks @ThinkDigitalSoftware for https://github.com/rikulo/socket.io-dart/pull/15
  • Thanks @guilhermecaldas for https://github.com/rikulo/socket.io-dart/pull/16
  • Thanks @jodinathan for https://github.com/rikulo/socket.io-dart/pull/17
  • Thanks @jodinathan for https://github.com/rikulo/socket.io-dart/pull/18
  • Thanks @nicobritos for https://github.com/rikulo/socket.io-dart/pull/46
  • Thanks @nicobritos for https://github.com/rikulo/socket.io-dart/pull/47

所屬分類

依賴

依賴清單 4 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。