network chunk v5
This commit is contained in:
@@ -20,7 +20,7 @@ export class TcpClientCommunicator extends SocketCommunicatorBase {
|
|||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
this.aesKey = null;
|
this.aesKey = null;
|
||||||
this.aesIv = null;
|
this.aesIv = null;
|
||||||
this.serverPublicKey = null;c
|
this.serverPublicKey = null;
|
||||||
this.isAesKeySetFlag = false;
|
this.isAesKeySetFlag = false;
|
||||||
this.chunkBuffers = {}; // Initialize chunk buffer for reassembling messages
|
this.chunkBuffers = {}; // Initialize chunk buffer for reassembling messages
|
||||||
}
|
}
|
||||||
@@ -91,6 +91,7 @@ export class TcpClientCommunicator extends SocketCommunicatorBase {
|
|||||||
const chunkWithHeader = `${chunkHeader}|${chunk}`;
|
const chunkWithHeader = `${chunkHeader}|${chunk}`;
|
||||||
|
|
||||||
await this.writeToSocket(chunkWithHeader);
|
await this.writeToSocket(chunkWithHeader);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 300)); // Simulate network delay
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -100,6 +100,8 @@ export class TcpServerCommunicator extends SocketCommunicatorBase {
|
|||||||
const [headerJson, chunkContent] = incomingMessage.split('|');
|
const [headerJson, chunkContent] = incomingMessage.split('|');
|
||||||
const header = JSON.parse(headerJson);
|
const header = JSON.parse(headerJson);
|
||||||
|
|
||||||
|
console.log(`\n\n${incomingMessage}\n\n`);
|
||||||
|
|
||||||
// Initialize chunk array if this is the first chunk for this messageId
|
// Initialize chunk array if this is the first chunk for this messageId
|
||||||
if (!this.chunkBuffers[header.messageId]) {
|
if (!this.chunkBuffers[header.messageId]) {
|
||||||
this.chunkBuffers[header.messageId] = new Array(header.totalChunks);
|
this.chunkBuffers[header.messageId] = new Array(header.totalChunks);
|
||||||
@@ -158,6 +160,7 @@ export class TcpServerCommunicator extends SocketCommunicatorBase {
|
|||||||
const chunkWithHeader = `${chunkHeader}|${chunk}`;
|
const chunkWithHeader = `${chunkHeader}|${chunk}`;
|
||||||
|
|
||||||
await this.writeToSocket(chunkWithHeader);
|
await this.writeToSocket(chunkWithHeader);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 300)); // Simulate network delay
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user