Closed rockneverdies55 closed 2 years ago
Started to call client.destroy()
within the callback of client.write()
and that seems to fix the issue.
const sendDataViaTcpSocket = async (data, host, port) => {
const p = new Promise(resolve => {
try {
client = TcpSocket.createConnection({host, port}, () => {
client.write(data, 'utf8', async () => {
client.destroy();
resolve(true);
});
});
} catch (e) {
resolve(false);
}
});//promise
return p;
};
I need to send the same data blob to multiple devices in the local network.
After the first target device receives the data, app completely exits suddenly. Is there anything suspicious in my code that catches your attention immediately that could be improved? I'm very new to sockets idea and just can't figure out the culprit in this case.