mirror of
https://github.com/Linloir/Simple-TCP-Client.git
synced 2025-12-17 00:38:11 +08:00
API adjustment
- Change payload length indicator: 4b -> 8b
This commit is contained in:
parent
3c6b5d64e3
commit
cf9e6b26b5
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-11 09:44:03
|
||||
* @LastEditTime : 2022-10-15 11:14:21
|
||||
* @LastEditTime : 2022-10-18 14:45:20
|
||||
* @Description : Abstract TCP request class
|
||||
*/
|
||||
|
||||
@ -64,7 +64,7 @@ abstract class TCPRequest {
|
||||
var jsonString = toJSON();
|
||||
var requestLength = jsonString.length;
|
||||
yield Uint8List(4)..buffer.asInt32List()[0] = requestLength;
|
||||
yield Uint8List(4)..buffer.asInt32List()[0] = 0;
|
||||
yield Uint8List(8)..buffer.asInt64List()[0] = 0;
|
||||
yield Uint8List.fromList(jsonString.codeUnits);
|
||||
}
|
||||
}
|
||||
@ -167,7 +167,7 @@ class SendMessageRequest extends TCPRequest {
|
||||
var jsonString = toJSON();
|
||||
var requestLength = jsonString.length;
|
||||
yield Uint8List(4)..buffer.asInt32List()[0] = requestLength;
|
||||
yield Uint8List(4)..buffer.asInt32List()[0] = (await _message.payload?.file.length()) ?? 0;
|
||||
yield Uint8List(8)..buffer.asInt64List()[0] = (await _message.payload?.file.length()) ?? 0;
|
||||
yield Uint8List.fromList(jsonString.codeUnits);
|
||||
if(_message.payload != null) {
|
||||
var fileStream = _message.payload!.file.openRead();
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-11 09:42:05
|
||||
* @LastEditTime : 2022-10-18 11:27:46
|
||||
* @LastEditTime : 2022-10-18 14:50:33
|
||||
* @Description : TCP repository
|
||||
*/
|
||||
|
||||
@ -149,12 +149,12 @@ class TCPRepository {
|
||||
while(true) {
|
||||
if(responseLength == 0 && payloadLength == 0 && _payloadPullStreamController.isClosed) {
|
||||
//New request
|
||||
if(buffer.length >= 8) {
|
||||
if(buffer.length >= 12) {
|
||||
//Buffered data has more than 8 bytes, enough to read request length and body length
|
||||
responseLength = Uint8List.fromList(buffer.sublist(0, 4)).buffer.asInt32List()[0];
|
||||
payloadLength = Uint8List.fromList(buffer.sublist(4, 8)).buffer.asInt32List()[0];
|
||||
payloadLength = Uint8List.fromList(buffer.sublist(4, 12)).buffer.asInt64List()[0];
|
||||
//Clear the length indicator bytes
|
||||
buffer.removeRange(0, 8);
|
||||
buffer.removeRange(0, 12);
|
||||
//Create a pull stream for payload file
|
||||
_payloadPullStreamController = StreamController();
|
||||
//Create a future that listens to the status of the payload transmission
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user