heart beat 작업중
This commit is contained in:
parent
fe30af98db
commit
7680ba8103
6 changed files with 171 additions and 15 deletions
|
|
@ -23,13 +23,14 @@ public static partial class MessageCommonReflection {
|
|||
byte[] descriptorData = global::System.Convert.FromBase64String(
|
||||
string.Concat(
|
||||
"ChRtZXNzYWdlX2NvbW1vbi5wcm90byI7CgpQYWNrZXRCYXNlEhAKCHR5cGVO",
|
||||
"YW1lGAEgASgJEg0KBW5vbmNlGAIgASgFEgwKBGRhdGEYAyABKAwiLgoMVGVt",
|
||||
"cGxhdGVEYXRhEg0KBWluZGV4GAEgASgFEg8KB21lc3NhZ2UYAiABKAliBnBy",
|
||||
"b3RvMw=="));
|
||||
"YW1lGAEgASgJEg0KBW5vbmNlGAIgASgFEgwKBGRhdGEYAyABKAwiCwoJSGVh",
|
||||
"cnRCZWF0Ii4KDFRlbXBsYXRlRGF0YRINCgVpbmRleBgBIAEoBRIPCgdtZXNz",
|
||||
"YWdlGAIgASgJYgZwcm90bzM="));
|
||||
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
|
||||
new pbr::FileDescriptor[] { },
|
||||
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
|
||||
new pbr::GeneratedClrTypeInfo(typeof(global::PacketBase), global::PacketBase.Parser, new[]{ "TypeName", "Nonce", "Data" }, null, null, null, null),
|
||||
new pbr::GeneratedClrTypeInfo(typeof(global::HeartBeat), global::HeartBeat.Parser, null, null, null, null, null),
|
||||
new pbr::GeneratedClrTypeInfo(typeof(global::TemplateData), global::TemplateData.Parser, new[]{ "Index", "Message" }, null, null, null, null)
|
||||
}));
|
||||
}
|
||||
|
|
@ -222,6 +223,107 @@ public sealed partial class PacketBase : pb::IMessage<PacketBase> {
|
|||
|
||||
}
|
||||
|
||||
public sealed partial class HeartBeat : pb::IMessage<HeartBeat> {
|
||||
private static readonly pb::MessageParser<HeartBeat> _parser = new pb::MessageParser<HeartBeat>(() => new HeartBeat());
|
||||
private pb::UnknownFieldSet _unknownFields;
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
public static pb::MessageParser<HeartBeat> Parser { get { return _parser; } }
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
public static pbr::MessageDescriptor Descriptor {
|
||||
get { return global::MessageCommonReflection.Descriptor.MessageTypes[1]; }
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
pbr::MessageDescriptor pb::IMessage.Descriptor {
|
||||
get { return Descriptor; }
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
public HeartBeat() {
|
||||
OnConstruction();
|
||||
}
|
||||
|
||||
partial void OnConstruction();
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
public HeartBeat(HeartBeat other) : this() {
|
||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
public HeartBeat Clone() {
|
||||
return new HeartBeat(this);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
public override bool Equals(object other) {
|
||||
return Equals(other as HeartBeat);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
public bool Equals(HeartBeat other) {
|
||||
if (ReferenceEquals(other, null)) {
|
||||
return false;
|
||||
}
|
||||
if (ReferenceEquals(other, this)) {
|
||||
return true;
|
||||
}
|
||||
return Equals(_unknownFields, other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
public override int GetHashCode() {
|
||||
int hash = 1;
|
||||
if (_unknownFields != null) {
|
||||
hash ^= _unknownFields.GetHashCode();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
public override string ToString() {
|
||||
return pb::JsonFormatter.ToDiagnosticString(this);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
public void WriteTo(pb::CodedOutputStream output) {
|
||||
if (_unknownFields != null) {
|
||||
_unknownFields.WriteTo(output);
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
public int CalculateSize() {
|
||||
int size = 0;
|
||||
if (_unknownFields != null) {
|
||||
size += _unknownFields.CalculateSize();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
public void MergeFrom(HeartBeat other) {
|
||||
if (other == null) {
|
||||
return;
|
||||
}
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
public void MergeFrom(pb::CodedInputStream input) {
|
||||
uint tag;
|
||||
while ((tag = input.ReadTag()) != 0) {
|
||||
switch(tag) {
|
||||
default:
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed partial class TemplateData : pb::IMessage<TemplateData> {
|
||||
private static readonly pb::MessageParser<TemplateData> _parser = new pb::MessageParser<TemplateData>(() => new TemplateData());
|
||||
private pb::UnknownFieldSet _unknownFields;
|
||||
|
|
@ -230,7 +332,7 @@ public sealed partial class TemplateData : pb::IMessage<TemplateData> {
|
|||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
public static pbr::MessageDescriptor Descriptor {
|
||||
get { return global::MessageCommonReflection.Descriptor.MessageTypes[1]; }
|
||||
get { return global::MessageCommonReflection.Descriptor.MessageTypes[2]; }
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ message PacketBase {
|
|||
bytes data = 3;
|
||||
}
|
||||
|
||||
message HeartBeat {}
|
||||
|
||||
message TemplateData {
|
||||
int32 index = 1;
|
||||
string message = 2;
|
||||
|
|
|
|||
|
|
@ -91,6 +91,38 @@ class PacketBase extends $pb.GeneratedMessage {
|
|||
void clearData() => clearField(3);
|
||||
}
|
||||
|
||||
class HeartBeat extends $pb.GeneratedMessage {
|
||||
factory HeartBeat() => create();
|
||||
HeartBeat._() : super();
|
||||
factory HeartBeat.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
|
||||
factory HeartBeat.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
|
||||
|
||||
static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'HeartBeat', createEmptyInstance: 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')
|
||||
HeartBeat clone() => HeartBeat()..mergeFromMessage(this);
|
||||
@$core.Deprecated(
|
||||
'Using this can add significant overhead to your binary. '
|
||||
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
|
||||
'Will be removed in next major version')
|
||||
HeartBeat copyWith(void Function(HeartBeat) updates) => super.copyWith((message) => updates(message as HeartBeat)) as HeartBeat;
|
||||
|
||||
$pb.BuilderInfo get info_ => _i;
|
||||
|
||||
@$core.pragma('dart2js:noInline')
|
||||
static HeartBeat create() => HeartBeat._();
|
||||
HeartBeat createEmptyInstance() => create();
|
||||
static $pb.PbList<HeartBeat> createRepeated() => $pb.PbList<HeartBeat>();
|
||||
@$core.pragma('dart2js:noInline')
|
||||
static HeartBeat getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<HeartBeat>(create);
|
||||
static HeartBeat? _defaultInstance;
|
||||
}
|
||||
|
||||
class TemplateData extends $pb.GeneratedMessage {
|
||||
factory TemplateData({
|
||||
$core.int? index,
|
||||
|
|
|
|||
|
|
@ -28,6 +28,15 @@ final $typed_data.Uint8List packetBaseDescriptor = $convert.base64Decode(
|
|||
'CgpQYWNrZXRCYXNlEhoKCHR5cGVOYW1lGAEgASgJUgh0eXBlTmFtZRIUCgVub25jZRgCIAEoBV'
|
||||
'IFbm9uY2USEgoEZGF0YRgDIAEoDFIEZGF0YQ==');
|
||||
|
||||
@$core.Deprecated('Use heartBeatDescriptor instead')
|
||||
const HeartBeat$json = {
|
||||
'1': 'HeartBeat',
|
||||
};
|
||||
|
||||
/// Descriptor for `HeartBeat`. Decode as a `google.protobuf.DescriptorProto`.
|
||||
final $typed_data.Uint8List heartBeatDescriptor = $convert.base64Decode(
|
||||
'CglIZWFydEJlYXQ=');
|
||||
|
||||
@$core.Deprecated('Use templateDataDescriptor instead')
|
||||
const TemplateData$json = {
|
||||
'1': 'TemplateData',
|
||||
|
|
|
|||
|
|
@ -24,10 +24,16 @@ class ProtobufClient extends Communicator
|
|||
super.initialize({
|
||||
(TemplateData).toString() : TemplateData.fromBuffer
|
||||
});
|
||||
addListener(onHeartBeat);
|
||||
_socket.listen(onData, onError: onError)
|
||||
.asFuture().then(onDisconnected);
|
||||
}
|
||||
|
||||
void onHeartBeat(HeartBeat data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void addDisconnectListener(void Function(ProtobufClient) handler)
|
||||
{
|
||||
if(!_onDisconnectListenerList.contains(handler))
|
||||
|
|
|
|||
|
|
@ -4,26 +4,31 @@ import 'dart:io';
|
|||
import 'package:dart_framework/socket/packets/message_common.pb.dart';
|
||||
import 'package:dart_framework/socket/protobuf_client.dart';
|
||||
|
||||
class ProtobufServer
|
||||
abstract class ProtobufServer
|
||||
{
|
||||
late ServerSocket _server;
|
||||
List<ProtobufClient> _clientList = [];
|
||||
String _host;
|
||||
int _port;
|
||||
final String _host;
|
||||
final int _port;
|
||||
final ProtobufClient Function(Socket) _createNewClient;
|
||||
|
||||
ProtobufServer(this._host, this._port);
|
||||
ProtobufServer(this._host, this._port, this._createNewClient);
|
||||
|
||||
Future start() async
|
||||
{
|
||||
_server = await ServerSocket.bind(_host, _port);
|
||||
_server.listen((Socket socket) {
|
||||
var client = ProtobufClient(socket);
|
||||
var client = _createNewClient(socket);
|
||||
client.addDisconnectListener(onDisconnectedClient);
|
||||
client.addListener(onTestSocket);
|
||||
client.addListener(onTemplateData);
|
||||
_clientList.add(client);
|
||||
onClientConnected(client);
|
||||
});
|
||||
}
|
||||
|
||||
//implement in child
|
||||
void onClientConnected(ProtobufClient client);
|
||||
|
||||
void onDisconnectedClient(ProtobufClient client)
|
||||
{
|
||||
_clientList.remove(client);
|
||||
|
|
@ -31,12 +36,12 @@ class ProtobufServer
|
|||
print('Client disconnected');
|
||||
}
|
||||
|
||||
void onTestSocket(TemplateData data)
|
||||
void onTemplateData(TemplateData data)
|
||||
{
|
||||
print(data.message);
|
||||
var test = TemplateData();
|
||||
test.index = 3125;
|
||||
test.message = 'This message from flutter';
|
||||
_clientList[0].send(test);
|
||||
var template = TemplateData();
|
||||
template.index = 3125;
|
||||
template.message = 'This message from flutter';
|
||||
_clientList[0].send(template);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue