Skip to content

Latest commit

 

History

History
126 lines (82 loc) · 3.22 KB

README-ZH.md

File metadata and controls

126 lines (82 loc) · 3.22 KB

文档语言: English | 中文简体

FlutterSocket

build status Pub support

FlutterSocket是一个实用的跨平台socket插件,目前已经实现client端的基本功能:创建,连接,发送消息,收消息,断开连接等功能...

如果你需要其他的功能,可以在此基础上拓展

Demo

Demo

Video

video url: https://www.youtube.com/watch?v=fmtwYHeOvE0

添加依赖

dependencies:
  flutter_socket_plugin: lastest version  

使用示例

import 'package:flutter_socket_plugin/flutter_socket_plugin.dart';
  ///
  /// @Method: initSocket
  /// @Parameter:
  /// @ReturnType:
  /// @Description: init socket
  /// @author: waitwalker
  /// @Date: 2019-08-23
  ///
  initSocket() {
    
    /// init socket
    flutterSocket = FlutterSocket();

    /// listen connect callback
    flutterSocket.connectListener((data){
      print("connect listener data:$data");
    });

    /// listen error callback
    flutterSocket.errorListener((data){
      print("error listener data:$data");
    });

    /// listen receive callback
    flutterSocket.receiveListener((data){
      print("receive listener data:$data");
      if (data != null) {
        receiveMessage = receiveMessage + "\n" + data;
      }
      setState(() {

      });
    });

    /// listen disconnect callback
    flutterSocket.disconnectListener((data){
      print("disconnect listener data:$data");
    });

  }

示例

创建 socket :

await flutterSocket.createSocket("192.168.8.120", 10007, timeout: 20);

发起连接 connect :

flutterSocket.tryConnect();

发送消息 send :

flutterSocket.send(textEditingController.text);

断开连接 disconnect :

flutterSocket.tryDisconnect();

示例目录

你可以在这里查看FlutterSocket的全部示例.

未来

FlutterSocket目前实现了客户端基本String消息的收发,未来在条件允许的情况下,逐步完善功能,如果你急需一些功能,你可以在FlutterSocket的基础上继续添加功能,让FlutterSocket功能更加强大和完善!

Copyright & License

此项目为完全开源 ,license 是 MIT. 如果您喜欢,欢迎star.

Features and bugs

Please file feature requests and bugs at the issue tracker.

Flutter技术及其他交流群组

作者微信:dbzy_duzhao