import 'dart:io'; import 'dart:typed_data'; import 'package:eitc_erm_app/utils/logger.dart'; void main() { Socket socket; // 创建Socket连接 Socket.connect('192.168.1.1', 40009).then((Socket sock) { socket = sock; // 连接成功后的处理 logd('连接成功'); // 发送数据到服务器 socket.write('Hello from Flutter'); // 监听服务器发送的数据 socket.listen((List data) { logd('接收到数据:${String.fromCharCodes(data)}'); int nalLen; int SockBufUsed; int bytesRead = 0; int NalBufUsed = 0; Uint8List frame = Uint8List(500 * 1024); Uint8List SockBuf = Uint8List(8192 * 2); /*try { is = BufferedInputStream(sock.getInputStream()); } catch (e) { e.printStackTrace(); }*/ Uint8List bytes = Uint8List.fromList(data); }); }).catchError((error) { // 连接错误的处理 logd('连接错误:$error'); }); }