Made the communication even more stable, fixed bugs with modified client.

This commit is contained in:
jsrobson10 2019-03-30 21:27:36 +11:00
parent 62390df244
commit 2ea89f09b5
1 changed files with 9 additions and 3 deletions

12
main.js
View File

@ -115,6 +115,8 @@ function socket_init(socket, callback, ondata)
sock.sock = socket; sock.sock = socket;
sock.new = true; sock.new = true;
console.log("Connection from "+socket.localAdress);
// Wait for data // Wait for data
sock.sock.on('data', function(data) sock.sock.on('data', function(data)
{ {
@ -144,15 +146,18 @@ function socket_init(socket, callback, ondata)
console.log("Encrypted the key"); console.log("Encrypted the key");
// Send the size of the key to the client // Send the size of the key to the client
sock.sock.write(key_encrypted.length.toString()); sock.sock.write(key_encrypted.length.toString()+"\n");
console.log("Sent the size of the key:", key_encrypted.length) console.log("Sent the size of the key:", key_encrypted.length)
// Send the key to the client // Send the key to the client
sock.sock.write(key_encrypted.toString()); sock.sock.write(key_encrypted.toString()+"\n");
console.log("Sent the key to the client"); console.log("Sent the key to the client");
// Send the done signal
//sock.sock.write("done"+"\n");
// Call the callback // Call the callback
setTimeout(callback, 10, sock); setTimeout(callback, 1000, sock);
}); });
} }
@ -168,6 +173,7 @@ function socket_init(socket, callback, ondata)
for(var i=0;i<data.length-1;i++) for(var i=0;i<data.length-1;i++)
{ {
// Send the parsed data to the callback // Send the parsed data to the callback
console.log(data[i]);
ondata(JSON.parse(data[i])); ondata(JSON.parse(data[i]));
} }
} }