搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目

暂无相关数据。