diff --git a/lib/communicator.dart b/lib/communicator.dart index 111e273..1f498db 100644 --- a/lib/communicator.dart +++ b/lib/communicator.dart @@ -19,7 +19,7 @@ abstract class Communicator { if(!_instanceGenerator.containsKey(type)) { - throw Exception('Must set protobuf packet creator before use it.'); + throw Exception('Must set protobuf packet creator before use it. Type: ${(T).toString()}'); } return _instanceGenerator[type] as T Function(List); } diff --git a/lib/socket/protobuf_client.dart b/lib/socket/protobuf_client.dart index 92a4b69..b645212 100644 --- a/lib/socket/protobuf_client.dart +++ b/lib/socket/protobuf_client.dart @@ -14,16 +14,20 @@ class ProtobufClient extends Communicator final int _headerSize = 4; final Socket _socket; int? _length = null; + bool _isAlive = false; late List _arrivedData = []; List _onDisconnectListenerList = []; - ProtobufClient(this._socket) + ProtobufClient(this._socket, Map)> parserMap) { print('Connected New Client'); - super.initialize({ - (TemplateData).toString() : TemplateData.fromBuffer + _isAlive = true; + parserMap.addAll({ + (TemplateData).toString() : TemplateData.fromBuffer, + (HeartBeat).toString() : HeartBeat.fromBuffer }); + super.initialize(parserMap); addListener(onHeartBeat); _socket.listen(onData, onError: onError) .asFuture().then(onDisconnected); diff --git a/lib/socket/protobuf_server.dart b/lib/socket/protobuf_server.dart index 69b52e7..a558fd9 100644 --- a/lib/socket/protobuf_server.dart +++ b/lib/socket/protobuf_server.dart @@ -3,15 +3,16 @@ import 'dart:io'; import 'package:dart_framework/socket/packets/message_common.pb.dart'; import 'package:dart_framework/socket/protobuf_client.dart'; +import 'package:dart_framework/utils/system_util.dart'; abstract class ProtobufServer { - late ServerSocket _server; List _clientList = []; + late ServerSocket _server; final String _host; final int _port; final ProtobufClient Function(Socket) _createNewClient; - + ProtobufServer(this._host, this._port, this._createNewClient); Future start() async @@ -24,6 +25,7 @@ abstract class ProtobufServer _clientList.add(client); onClientConnected(client); }); + return simpleFuture; } //implement in child