FlutterSocket is a practical cross-platform socket plugin. At present, it has realized the basic functions of client side: create, connect, send, receive, disconnect and so on.
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");
});
}
Create socket
:
await flutterSocket.createSocket("192.168.8.120", 10007, timeout: 20);
Connect connect
:
flutterSocket.tryConnect();
Send message send
:
flutterSocket.send(textEditingController.text);
Disconnect disconnect
:
flutterSocket.tryDisconnect();
you can find all examples code here.
FlutterSocket currently implements the sending and receiving of basic String messages on the client. In the future, it will gradually improve its functions if conditions permit. If you need some functions urgently, you can continue to add functions on the basis of FlutterSocket to make the function of FlutterSocket more powerful and perfect.
This project is completely open source and the license is MIT. If you like, welcome star.
Please file feature requests and bugs at the issue tracker.
wechat:dbzy_duzhao