mirror of
https://github.com/Linloir/Simple-TCP-Server.git
synced 2025-12-18 08:28:12 +08:00
API adjustment
- Change payload length indicator bytes length: 4b -> 8b
This commit is contained in:
parent
bdfeb07927
commit
522e0712e7
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author : Linloir
|
* @Author : Linloir
|
||||||
* @Date : 2022-10-08 15:10:04
|
* @Date : 2022-10-08 15:10:04
|
||||||
* @LastEditTime : 2022-10-17 22:53:17
|
* @LastEditTime : 2022-10-18 14:50:17
|
||||||
* @Description :
|
* @Description :
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -108,12 +108,12 @@ class TCPController {
|
|||||||
while(true) {
|
while(true) {
|
||||||
if(requestLength == 0 && payloadLength == 0 && _payloadPullStreamController.isClosed) {
|
if(requestLength == 0 && payloadLength == 0 && _payloadPullStreamController.isClosed) {
|
||||||
//New request
|
//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
|
//Buffered data has more than 8 bytes, enough to read request length and body length
|
||||||
requestLength = Uint8List.fromList(buffer.sublist(0, 4)).buffer.asInt32List()[0];
|
requestLength = 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
|
//Clear the length indicator bytes
|
||||||
buffer.removeRange(0, 8);
|
buffer.removeRange(0, 12);
|
||||||
//Initialize payload transmission controller
|
//Initialize payload transmission controller
|
||||||
_payloadPullStreamController = StreamController();
|
_payloadPullStreamController = StreamController();
|
||||||
//Create a future that listens to the status of the payload transmission
|
//Create a future that listens to the status of the payload transmission
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author : Linloir
|
* @Author : Linloir
|
||||||
* @Date : 2022-10-08 22:40:47
|
* @Date : 2022-10-08 22:40:47
|
||||||
* @LastEditTime : 2022-10-12 13:53:06
|
* @LastEditTime : 2022-10-18 14:44:49
|
||||||
* @Description :
|
* @Description :
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ class TCPResponse {
|
|||||||
int get payloadLength => payloadFile?.lengthSync() ?? 0;
|
int get payloadLength => payloadFile?.lengthSync() ?? 0;
|
||||||
Stream<List<int>> get stream async* {
|
Stream<List<int>> get stream async* {
|
||||||
yield Uint8List(4)..buffer.asInt32List()[0] = responseLength;
|
yield Uint8List(4)..buffer.asInt32List()[0] = responseLength;
|
||||||
yield Uint8List(4)..buffer.asInt32List()[0] = payloadLength;
|
yield Uint8List(8)..buffer.asInt64List()[0] = payloadLength;
|
||||||
yield Uint8List.fromList(responseJson.codeUnits);
|
yield Uint8List.fromList(responseJson.codeUnits);
|
||||||
if(payloadFile != null) {
|
if(payloadFile != null) {
|
||||||
yield await payloadFile!.readAsBytes();
|
yield await payloadFile!.readAsBytes();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user