Browse Source

增加socket操作代码

dart3_last
fff 4 months ago
parent
commit
93d6e9ca4d
  1. 2
      android/app/build.gradle
  2. 30
      android/build.gradle
  3. 5
      android/gradle.properties
  4. 2
      android/gradle/wrapper/gradle-wrapper.properties
  5. 72
      lib/im/Proto.dart
  6. 60
      lib/im/SocketClient.dart
  7. 160
      lib/im/out/auth.pb.dart
  8. 11
      lib/im/out/auth.pbenum.dart
  9. 43
      lib/im/out/auth.pbjson.dart
  10. 14
      lib/im/out/auth.pbserver.dart
  11. 272
      lib/im/out/message.pb.dart
  12. 36
      lib/im/out/message.pbenum.dart
  13. 85
      lib/im/out/message.pbjson.dart
  14. 14
      lib/im/out/message.pbserver.dart
  15. 2
      lib/main.dart
  16. 26
      lib/main_page.dart
  17. 388
      pubspec.lock
  18. 2
      pubspec.yaml

2
android/app/build.gradle

@ -106,7 +106,7 @@ android {
defaultConfig {
applicationId "com.zsw.huixiang"
minSdkVersion 21
targetSdkVersion 31
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName

30
android/build.gradle

@ -1,6 +1,9 @@
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
maven { url "https://www.jitpack.io" }
maven {url 'https://developer.huawei.com/repo/'}
maven { url 'https://repo1.maven.org/maven2/' }
maven {
url 'https://maven.aliyun.com/repository/google'
}
@ -11,28 +14,22 @@ buildscript {
allowInsecureProtocol = true
url 'http://maven.aliyun.com/nexus/content/groups/public'
}
// google()
// jcenter()
maven {
allowInsecureProtocol = true
url "http://mvn.mob.com/android"
}
maven { url "https://www.jitpack.io" }
maven {url 'https://developer.huawei.com/repo/'}
maven { url 'https://repo1.maven.org/maven2/' }
maven { url 'https://developer.huawei.com/repo/' }
}
dependencies {
// classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:7.2.0'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
classpath 'com.mob.sdk:MobSDK:+'
classpath 'com.android.tools.build:gradle:3.4.0'
classpath fileTree(include:['*.jar'], dir:'libs')
classpath 'com.umeng.umsdk:common:9.4.7'
classpath 'com.umeng.umsdk:asms:1.4.0'
classpath 'com.umeng.umsdk:abtest:1.0.0'
classpath 'com.umeng.umsdk:common:9.4.7'
classpath 'com.umeng.umsdk:asms:1.4.0'
classpath 'com.umeng.umsdk:abtest:1.0.0'
}
}
@ -41,22 +38,15 @@ allprojects {
maven {
url 'https://maven.aliyun.com/repository/google'
}
maven {
url 'https://maven.aliyun.com/repository/jcenter'
}
maven {
allowInsecureProtocol = true
url 'http://maven.aliyun.com/nexus/content/groups/public'
}
// google()
// jcenter()
maven {
allowInsecureProtocol = true
url "http://mvn.mob.com/android"
}
maven { url "https://www.jitpack.io" }
maven { url 'https://developer.huawei.com/repo/'}
maven { url 'https://repo1.maven.org/maven2/' }
google()
}
}
@ -66,6 +56,6 @@ subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}

5
android/gradle.properties

@ -4,7 +4,4 @@ android.useAndroidX=true
android.enableJetifier=true
MobSDK.mobEnv=x
MobSDK.spEdition=FP
android.injected.testOnly=false
#org.gradle.jvmargs=-Xmx1536M --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
android.injected.testOnly=false

2
android/gradle/wrapper/gradle-wrapper.properties vendored

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

72
lib/im/Proto.dart

@ -0,0 +1,72 @@
import 'dart:typed_data';
/**
*
*
*
*
* 4 +body
* 2 header长度
* 2 1
* 4 15
* 4 1
* body 2048-16
* 2048
*/
class Proto {
static const int HEADER_LENGTH = 16; // 16
static const int VERSION = 1;
int operation;
int seqId;
Uint8List body;
Proto(this.operation, this.seqId, this.body);
Uint8List toBytes() {
final buffer = BytesBuilder();
buffer.add(_intToBytes(HEADER_LENGTH + body.length, 4));
buffer.add(_shortToBytes(HEADER_LENGTH, 2));
buffer.add(_shortToBytes(VERSION, 2));
buffer.add(_intToBytes(operation, 4));
buffer.add(_intToBytes(seqId, 4));
buffer.add(body);
return buffer.toBytes();
}
static Proto fromBytes(Uint8List data) {
final buffer = ByteData.sublistView(data);
int offset = 0;
int packetLen = buffer.getInt32(offset, Endian.big);
offset += 4;
int headerLen = buffer.getInt16(offset, Endian.big);
offset += 2;
int version = buffer.getInt16(offset, Endian.big);
offset += 2;
int operation = buffer.getInt32(offset, Endian.big);
offset += 4;
int seqId = buffer.getInt32(offset, Endian.big);
offset += 4;
Uint8List body = data.sublist(offset);
return Proto(operation, seqId, body);
}
List<int> _intToBytes(int value, int length) {
final bytes = ByteData(length);
bytes.setInt32(0, value, Endian.big);
return bytes.buffer.asUint8List();
}
List<int> _shortToBytes(int value, int length) {
final bytes = ByteData(length);
bytes.setInt16(0, value, Endian.big);
return bytes.buffer.asUint8List();
}
}

60
lib/im/SocketClient.dart

@ -0,0 +1,60 @@
import 'dart:convert';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:huixiang/im/Proto.dart';
import 'package:huixiang/im/out/auth.pb.dart';
import 'package:huixiang/im/out/message.pb.dart';
class SocketClient {
Socket _socket;
connect() async {
_socket = await Socket.connect('192.168.10.129', 9090);
_socket.listen((data) {
print(data);
print("socket-listen");
Proto proto = Proto.fromBytes(data);
print("socket-listen: $proto");
MsgData data1 = MsgData.fromBuffer(proto.body);
print('收到来自:${data1.from},消息内容: ${utf8.decode(data1.data)} ');
callbacks.forEach((callback) {
callback.call(data1);
});
});
}
List<Function> callbacks = [];
addCallback(Function callback) {
callbacks.add(callback);
}
removeCallback(Function callback) {
callbacks.remove(callback);
}
authRequest(String token) {
final authReq = AuthReq()
..uid = 1
..token = '123456';
final authReqBytes = authReq.writeToBuffer();
final proto = Proto(1, 1, authReqBytes); // operation seqId 1
final protoBytes = proto.toBytes();
_socket.add(protoBytes);
}
sendMessage(var to, String content) {
Uint8List data = utf8.encode(content);
MsgData msgData = MsgData(to: to,from: 2,type: MsgType.SINGLE_TEXT,data: data);
final proto2 = Proto(5,1,msgData.writeToBuffer());
_socket.add(proto2.toBytes());
}
}

160
lib/im/out/auth.pb.dart

@ -0,0 +1,160 @@
//
// Generated code. Do not modify.
// source: auth.proto
//
// @dart = 2.12
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
// ignore_for_file: constant_identifier_names, library_prefixes
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
import 'dart:core' as $core;
import 'package:protobuf/protobuf.dart' as $pb;
class AuthReq extends $pb.GeneratedMessage {
factory AuthReq({
$core.int? uid,
$core.String? token,
}) {
final $result = create();
if (uid != null) {
$result.uid = uid;
}
if (token != null) {
$result.token = token;
}
return $result;
}
AuthReq._() : super();
factory AuthReq.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory AuthReq.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'AuthReq', createEmptyInstance: create)
..a<$core.int>(1, _omitFieldNames ? '' : 'uid', $pb.PbFieldType.OU3)
..aOS(2, _omitFieldNames ? '' : 'token')
..hasRequiredFields = false
;
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
AuthReq clone() => AuthReq()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
AuthReq copyWith(void Function(AuthReq) updates) => super.copyWith((message) => updates(message as AuthReq)) as AuthReq;
$pb.BuilderInfo get info_ => _i;
@$core.pragma('dart2js:noInline')
static AuthReq create() => AuthReq._();
AuthReq createEmptyInstance() => create();
static $pb.PbList<AuthReq> createRepeated() => $pb.PbList<AuthReq>();
@$core.pragma('dart2js:noInline')
static AuthReq getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<AuthReq>(create);
static AuthReq? _defaultInstance;
@$pb.TagNumber(1)
$core.int get uid => $_getIZ(0);
@$pb.TagNumber(1)
set uid($core.int v) { $_setUnsignedInt32(0, v); }
@$pb.TagNumber(1)
$core.bool hasUid() => $_has(0);
@$pb.TagNumber(1)
void clearUid() => clearField(1);
@$pb.TagNumber(2)
$core.String get token => $_getSZ(1);
@$pb.TagNumber(2)
set token($core.String v) { $_setString(1, v); }
@$pb.TagNumber(2)
$core.bool hasToken() => $_has(1);
@$pb.TagNumber(2)
void clearToken() => clearField(2);
}
class AuthResp extends $pb.GeneratedMessage {
factory AuthResp({
$core.int? uid,
$core.int? code,
$core.String? message,
}) {
final $result = create();
if (uid != null) {
$result.uid = uid;
}
if (code != null) {
$result.code = code;
}
if (message != null) {
$result.message = message;
}
return $result;
}
AuthResp._() : super();
factory AuthResp.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory AuthResp.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'AuthResp', createEmptyInstance: create)
..a<$core.int>(1, _omitFieldNames ? '' : 'uid', $pb.PbFieldType.OU3)
..a<$core.int>(2, _omitFieldNames ? '' : 'code', $pb.PbFieldType.OU3)
..aOS(3, _omitFieldNames ? '' : 'message')
..hasRequiredFields = false
;
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
AuthResp clone() => AuthResp()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
AuthResp copyWith(void Function(AuthResp) updates) => super.copyWith((message) => updates(message as AuthResp)) as AuthResp;
$pb.BuilderInfo get info_ => _i;
@$core.pragma('dart2js:noInline')
static AuthResp create() => AuthResp._();
AuthResp createEmptyInstance() => create();
static $pb.PbList<AuthResp> createRepeated() => $pb.PbList<AuthResp>();
@$core.pragma('dart2js:noInline')
static AuthResp getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<AuthResp>(create);
static AuthResp? _defaultInstance;
@$pb.TagNumber(1)
$core.int get uid => $_getIZ(0);
@$pb.TagNumber(1)
set uid($core.int v) { $_setUnsignedInt32(0, v); }
@$pb.TagNumber(1)
$core.bool hasUid() => $_has(0);
@$pb.TagNumber(1)
void clearUid() => clearField(1);
@$pb.TagNumber(2)
$core.int get code => $_getIZ(1);
@$pb.TagNumber(2)
set code($core.int v) { $_setUnsignedInt32(1, v); }
@$pb.TagNumber(2)
$core.bool hasCode() => $_has(1);
@$pb.TagNumber(2)
void clearCode() => clearField(2);
@$pb.TagNumber(3)
$core.String get message => $_getSZ(2);
@$pb.TagNumber(3)
set message($core.String v) { $_setString(2, v); }
@$pb.TagNumber(3)
$core.bool hasMessage() => $_has(2);
@$pb.TagNumber(3)
void clearMessage() => clearField(3);
}
const _omitFieldNames = $core.bool.fromEnvironment('protobuf.omit_field_names');
const _omitMessageNames = $core.bool.fromEnvironment('protobuf.omit_message_names');

11
lib/im/out/auth.pbenum.dart

@ -0,0 +1,11 @@
//
// Generated code. Do not modify.
// source: auth.proto
//
// @dart = 2.12
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
// ignore_for_file: constant_identifier_names, library_prefixes
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import

43
lib/im/out/auth.pbjson.dart

@ -0,0 +1,43 @@
//
// Generated code. Do not modify.
// source: auth.proto
//
// @dart = 2.12
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
// ignore_for_file: constant_identifier_names, library_prefixes
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
import 'dart:convert' as $convert;
import 'dart:core' as $core;
import 'dart:typed_data' as $typed_data;
@$core.Deprecated('Use authReqDescriptor instead')
const AuthReq$json = {
'1': 'AuthReq',
'2': [
{'1': 'uid', '3': 1, '4': 1, '5': 13, '10': 'uid'},
{'1': 'token', '3': 2, '4': 1, '5': 9, '10': 'token'},
],
};
/// Descriptor for `AuthReq`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List authReqDescriptor = $convert.base64Decode(
'CgdBdXRoUmVxEhAKA3VpZBgBIAEoDVIDdWlkEhQKBXRva2VuGAIgASgJUgV0b2tlbg==');
@$core.Deprecated('Use authRespDescriptor instead')
const AuthResp$json = {
'1': 'AuthResp',
'2': [
{'1': 'uid', '3': 1, '4': 1, '5': 13, '10': 'uid'},
{'1': 'code', '3': 2, '4': 1, '5': 13, '10': 'code'},
{'1': 'message', '3': 3, '4': 1, '5': 9, '10': 'message'},
],
};
/// Descriptor for `AuthResp`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List authRespDescriptor = $convert.base64Decode(
'CghBdXRoUmVzcBIQCgN1aWQYASABKA1SA3VpZBISCgRjb2RlGAIgASgNUgRjb2RlEhgKB21lc3'
'NhZ2UYAyABKAlSB21lc3NhZ2U=');

14
lib/im/out/auth.pbserver.dart

@ -0,0 +1,14 @@
//
// Generated code. Do not modify.
// source: auth.proto
//
// @dart = 2.12
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
// ignore_for_file: constant_identifier_names
// ignore_for_file: deprecated_member_use_from_same_package, library_prefixes
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
export 'auth.pb.dart';

272
lib/im/out/message.pb.dart

@ -0,0 +1,272 @@
//
// Generated code. Do not modify.
// source: message.proto
//
// @dart = 2.12
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
// ignore_for_file: constant_identifier_names, library_prefixes
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
import 'dart:core' as $core;
import 'package:protobuf/protobuf.dart' as $pb;
import 'message.pbenum.dart';
export 'message.pbenum.dart';
class MsgData extends $pb.GeneratedMessage {
factory MsgData({
$core.int? to,
$core.int? from,
$core.int? ctime,
MsgType? type,
$core.List<$core.int>? data,
}) {
final $result = create();
if (to != null) {
$result.to = to;
}
if (from != null) {
$result.from = from;
}
if (ctime != null) {
$result.ctime = ctime;
}
if (type != null) {
$result.type = type;
}
if (data != null) {
$result.data = data;
}
return $result;
}
MsgData._() : super();
factory MsgData.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory MsgData.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'MsgData', createEmptyInstance: create)
..a<$core.int>(1, _omitFieldNames ? '' : 'to', $pb.PbFieldType.OU3)
..a<$core.int>(2, _omitFieldNames ? '' : 'from', $pb.PbFieldType.OU3)
..a<$core.int>(3, _omitFieldNames ? '' : 'ctime', $pb.PbFieldType.OU3)
..e<MsgType>(4, _omitFieldNames ? '' : 'type', $pb.PbFieldType.OE, defaultOrMaker: MsgType.SINGLE_TEXT, valueOf: MsgType.valueOf, enumValues: MsgType.values)
..a<$core.List<$core.int>>(5, _omitFieldNames ? '' : 'data', $pb.PbFieldType.OY)
..hasRequiredFields = false
;
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
MsgData clone() => MsgData()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
MsgData copyWith(void Function(MsgData) updates) => super.copyWith((message) => updates(message as MsgData)) as MsgData;
$pb.BuilderInfo get info_ => _i;
@$core.pragma('dart2js:noInline')
static MsgData create() => MsgData._();
MsgData createEmptyInstance() => create();
static $pb.PbList<MsgData> createRepeated() => $pb.PbList<MsgData>();
@$core.pragma('dart2js:noInline')
static MsgData getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<MsgData>(create);
static MsgData? _defaultInstance;
@$pb.TagNumber(1)
$core.int get to => $_getIZ(0);
@$pb.TagNumber(1)
set to($core.int v) { $_setUnsignedInt32(0, v); }
@$pb.TagNumber(1)
$core.bool hasTo() => $_has(0);
@$pb.TagNumber(1)
void clearTo() => clearField(1);
@$pb.TagNumber(2)
$core.int get from => $_getIZ(1);
@$pb.TagNumber(2)
set from($core.int v) { $_setUnsignedInt32(1, v); }
@$pb.TagNumber(2)
$core.bool hasFrom() => $_has(1);
@$pb.TagNumber(2)
void clearFrom() => clearField(2);
@$pb.TagNumber(3)
$core.int get ctime => $_getIZ(2);
@$pb.TagNumber(3)
set ctime($core.int v) { $_setUnsignedInt32(2, v); }
@$pb.TagNumber(3)
$core.bool hasCtime() => $_has(2);
@$pb.TagNumber(3)
void clearCtime() => clearField(3);
@$pb.TagNumber(4)
MsgType get type => $_getN(3);
@$pb.TagNumber(4)
set type(MsgType v) { setField(4, v); }
@$pb.TagNumber(4)
$core.bool hasType() => $_has(3);
@$pb.TagNumber(4)
void clearType() => clearField(4);
@$pb.TagNumber(5)
$core.List<$core.int> get data => $_getN(4);
@$pb.TagNumber(5)
set data($core.List<$core.int> v) { $_setBytes(4, v); }
@$pb.TagNumber(5)
$core.bool hasData() => $_has(4);
@$pb.TagNumber(5)
void clearData() => clearField(5);
}
class MsgNotify extends $pb.GeneratedMessage {
factory MsgNotify({
$core.int? seq,
}) {
final $result = create();
if (seq != null) {
$result.seq = seq;
}
return $result;
}
MsgNotify._() : super();
factory MsgNotify.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory MsgNotify.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'MsgNotify', createEmptyInstance: create)
..a<$core.int>(1, _omitFieldNames ? '' : 'seq', $pb.PbFieldType.OU3)
..hasRequiredFields = false
;
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
MsgNotify clone() => MsgNotify()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
MsgNotify copyWith(void Function(MsgNotify) updates) => super.copyWith((message) => updates(message as MsgNotify)) as MsgNotify;
$pb.BuilderInfo get info_ => _i;
@$core.pragma('dart2js:noInline')
static MsgNotify create() => MsgNotify._();
MsgNotify createEmptyInstance() => create();
static $pb.PbList<MsgNotify> createRepeated() => $pb.PbList<MsgNotify>();
@$core.pragma('dart2js:noInline')
static MsgNotify getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<MsgNotify>(create);
static MsgNotify? _defaultInstance;
@$pb.TagNumber(1)
$core.int get seq => $_getIZ(0);
@$pb.TagNumber(1)
set seq($core.int v) { $_setUnsignedInt32(0, v); }
@$pb.TagNumber(1)
$core.bool hasSeq() => $_has(0);
@$pb.TagNumber(1)
void clearSeq() => clearField(1);
}
class MsgSync extends $pb.GeneratedMessage {
factory MsgSync({
$core.int? seq,
}) {
final $result = create();
if (seq != null) {
$result.seq = seq;
}
return $result;
}
MsgSync._() : super();
factory MsgSync.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory MsgSync.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'MsgSync', createEmptyInstance: create)
..a<$core.int>(1, _omitFieldNames ? '' : 'seq', $pb.PbFieldType.OU3)
..hasRequiredFields = false
;
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
MsgSync clone() => MsgSync()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
MsgSync copyWith(void Function(MsgSync) updates) => super.copyWith((message) => updates(message as MsgSync)) as MsgSync;
$pb.BuilderInfo get info_ => _i;
@$core.pragma('dart2js:noInline')
static MsgSync create() => MsgSync._();
MsgSync createEmptyInstance() => create();
static $pb.PbList<MsgSync> createRepeated() => $pb.PbList<MsgSync>();
@$core.pragma('dart2js:noInline')
static MsgSync getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<MsgSync>(create);
static MsgSync? _defaultInstance;
@$pb.TagNumber(1)
$core.int get seq => $_getIZ(0);
@$pb.TagNumber(1)
set seq($core.int v) { $_setUnsignedInt32(0, v); }
@$pb.TagNumber(1)
$core.bool hasSeq() => $_has(0);
@$pb.TagNumber(1)
void clearSeq() => clearField(1);
}
class MsgSyncData extends $pb.GeneratedMessage {
factory MsgSyncData({
$core.Iterable<MsgData>? messages,
}) {
final $result = create();
if (messages != null) {
$result.messages.addAll(messages);
}
return $result;
}
MsgSyncData._() : super();
factory MsgSyncData.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory MsgSyncData.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'MsgSyncData', createEmptyInstance: create)
..pc<MsgData>(1, _omitFieldNames ? '' : 'messages', $pb.PbFieldType.PM, subBuilder: MsgData.create)
..hasRequiredFields = false
;
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
MsgSyncData clone() => MsgSyncData()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
MsgSyncData copyWith(void Function(MsgSyncData) updates) => super.copyWith((message) => updates(message as MsgSyncData)) as MsgSyncData;
$pb.BuilderInfo get info_ => _i;
@$core.pragma('dart2js:noInline')
static MsgSyncData create() => MsgSyncData._();
MsgSyncData createEmptyInstance() => create();
static $pb.PbList<MsgSyncData> createRepeated() => $pb.PbList<MsgSyncData>();
@$core.pragma('dart2js:noInline')
static MsgSyncData getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<MsgSyncData>(create);
static MsgSyncData? _defaultInstance;
@$pb.TagNumber(1)
$core.List<MsgData> get messages => $_getList(0);
}
const _omitFieldNames = $core.bool.fromEnvironment('protobuf.omit_field_names');
const _omitMessageNames = $core.bool.fromEnvironment('protobuf.omit_message_names');

36
lib/im/out/message.pbenum.dart

@ -0,0 +1,36 @@
//
// Generated code. Do not modify.
// source: message.proto
//
// @dart = 2.12
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
// ignore_for_file: constant_identifier_names, library_prefixes
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
import 'dart:core' as $core;
import 'package:protobuf/protobuf.dart' as $pb;
class MsgType extends $pb.ProtobufEnum {
static const MsgType SINGLE_TEXT = MsgType._(0, _omitEnumNames ? '' : 'SINGLE_TEXT');
static const MsgType SINGLE_AUDIO = MsgType._(1, _omitEnumNames ? '' : 'SINGLE_AUDIO');
static const MsgType GROUP_TEXT = MsgType._(2, _omitEnumNames ? '' : 'GROUP_TEXT');
static const MsgType GROUP_AUDIO = MsgType._(3, _omitEnumNames ? '' : 'GROUP_AUDIO');
static const $core.List<MsgType> values = <MsgType> [
SINGLE_TEXT,
SINGLE_AUDIO,
GROUP_TEXT,
GROUP_AUDIO,
];
static final $core.Map<$core.int, MsgType> _byValue = $pb.ProtobufEnum.initByValue(values);
static MsgType? valueOf($core.int value) => _byValue[value];
const MsgType._($core.int v, $core.String n) : super(v, n);
}
const _omitEnumNames = $core.bool.fromEnvironment('protobuf.omit_enum_names');

85
lib/im/out/message.pbjson.dart

@ -0,0 +1,85 @@
//
// Generated code. Do not modify.
// source: message.proto
//
// @dart = 2.12
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
// ignore_for_file: constant_identifier_names, library_prefixes
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
import 'dart:convert' as $convert;
import 'dart:core' as $core;
import 'dart:typed_data' as $typed_data;
@$core.Deprecated('Use msgTypeDescriptor instead')
const MsgType$json = {
'1': 'MsgType',
'2': [
{'1': 'SINGLE_TEXT', '2': 0},
{'1': 'SINGLE_AUDIO', '2': 1},
{'1': 'GROUP_TEXT', '2': 2},
{'1': 'GROUP_AUDIO', '2': 3},
],
};
/// Descriptor for `MsgType`. Decode as a `google.protobuf.EnumDescriptorProto`.
final $typed_data.Uint8List msgTypeDescriptor = $convert.base64Decode(
'CgdNc2dUeXBlEg8KC1NJTkdMRV9URVhUEAASEAoMU0lOR0xFX0FVRElPEAESDgoKR1JPVVBfVE'
'VYVBACEg8KC0dST1VQX0FVRElPEAM=');
@$core.Deprecated('Use msgDataDescriptor instead')
const MsgData$json = {
'1': 'MsgData',
'2': [
{'1': 'to', '3': 1, '4': 1, '5': 13, '10': 'to'},
{'1': 'from', '3': 2, '4': 1, '5': 13, '10': 'from'},
{'1': 'ctime', '3': 3, '4': 1, '5': 13, '10': 'ctime'},
{'1': 'type', '3': 4, '4': 1, '5': 14, '6': '.MsgType', '10': 'type'},
{'1': 'data', '3': 5, '4': 1, '5': 12, '10': 'data'},
],
};
/// Descriptor for `MsgData`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List msgDataDescriptor = $convert.base64Decode(
'CgdNc2dEYXRhEg4KAnRvGAEgASgNUgJ0bxISCgRmcm9tGAIgASgNUgRmcm9tEhQKBWN0aW1lGA'
'MgASgNUgVjdGltZRIcCgR0eXBlGAQgASgOMgguTXNnVHlwZVIEdHlwZRISCgRkYXRhGAUgASgM'
'UgRkYXRh');
@$core.Deprecated('Use msgNotifyDescriptor instead')
const MsgNotify$json = {
'1': 'MsgNotify',
'2': [
{'1': 'seq', '3': 1, '4': 1, '5': 13, '10': 'seq'},
],
};
/// Descriptor for `MsgNotify`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List msgNotifyDescriptor = $convert.base64Decode(
'CglNc2dOb3RpZnkSEAoDc2VxGAEgASgNUgNzZXE=');
@$core.Deprecated('Use msgSyncDescriptor instead')
const MsgSync$json = {
'1': 'MsgSync',
'2': [
{'1': 'seq', '3': 1, '4': 1, '5': 13, '10': 'seq'},
],
};
/// Descriptor for `MsgSync`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List msgSyncDescriptor = $convert.base64Decode(
'CgdNc2dTeW5jEhAKA3NlcRgBIAEoDVIDc2Vx');
@$core.Deprecated('Use msgSyncDataDescriptor instead')
const MsgSyncData$json = {
'1': 'MsgSyncData',
'2': [
{'1': 'messages', '3': 1, '4': 3, '5': 11, '6': '.MsgData', '10': 'messages'},
],
};
/// Descriptor for `MsgSyncData`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List msgSyncDataDescriptor = $convert.base64Decode(
'CgtNc2dTeW5jRGF0YRIkCghtZXNzYWdlcxgBIAMoCzIILk1zZ0RhdGFSCG1lc3NhZ2Vz');

14
lib/im/out/message.pbserver.dart

@ -0,0 +1,14 @@
//
// Generated code. Do not modify.
// source: message.proto
//
// @dart = 2.12
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
// ignore_for_file: constant_identifier_names
// ignore_for_file: deprecated_member_use_from_same_package, library_prefixes
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
export 'message.pb.dart';

2
lib/main.dart

@ -14,6 +14,7 @@ import 'package:huixiang/community/community_details.dart';
import 'package:huixiang/community/release_dynamic.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/home/founder_story_page.dart';
import 'package:huixiang/im/SocketClient.dart';
import 'package:huixiang/integral/integral_detailed_page.dart';
import 'package:huixiang/integral/integral_page.dart';
import 'package:huixiang/integral_store/integral_store_details_page.dart';
@ -216,6 +217,7 @@ void main() async {
final SocketClient socketClient = new SocketClient();
EventBus eventBus = EventBus(sync: true);
Route lastRoutePage;

26
lib/main_page.dart

@ -9,6 +9,8 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:huixiang/community/community_page.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/home/home_page.dart';
import 'package:huixiang/im/Proto.dart';
import 'package:huixiang/im/out/message.pb.dart';
import 'package:huixiang/main.dart';
import 'package:huixiang/mine/mine_page.dart';
import 'package:huixiang/retrofit/data/app_update.dart';
@ -90,9 +92,33 @@ class _MainPage extends State<MainPage> with WidgetsBindingObserver {
}
}
connectSocket() async {
final socket = await Socket.connect('192.168.10.129', 9090);
//
socket.listen((Uint8List data) {
print("123");
Proto proto = Proto.fromBytes(data);
print("1234,$proto");
MsgData data1 = MsgData.fromBuffer(proto.body);
print('收到来自:${data1.from},消息内容: ${utf8.decode(data1.data)} ');
}, onDone: () {
print('Server closed connection');
socket.destroy();
}, onError: (error) {
print('Error: $error');
socket.destroy();
});
}
@override
void initState() {
super.initState();
connectSocket();
pageController = PageController(
initialPage:
widget.arguments != null && widget.arguments["index"] != null

388
pubspec.lock

File diff suppressed because it is too large Load Diff

2
pubspec.yaml

@ -126,6 +126,8 @@ dependencies:
syncfusion_flutter_datepicker: ^19.4.38
protobuf: ^3.1.0
dev_dependencies:
flutter_test:
sdk: flutter

Loading…
Cancel
Save