You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using socket.io-stream library to transfer files between 2 node servers.
Server A: (Send File)
var clientIO = require('socket.io-client');
var ss = require('socket.io-stream');
var clientSocket= clientIO(`http://ServerB_Address`);
clientSocket.on('error', (error) => {
console.log(error);
});
var stream = ss.createStream({objectMode: true});
ss(clientSocket).emit('send-file', stream, data);
var uploadedBytes = 0;
var from = 0;
var reader = fs.createReadStream(filePath, {start: from});
reader.pipe(stream)
.on('error', (error) => {
console.log(error);
})
.on('data', (chunk) => {
uploadedBytes += Buffer.byteLength(chunk);
});
Server B: (Receive File)
var fs = require('fs');
var io = require('socket.io')(http);
var ss = require('socket.io-stream');
io.on('connection', (socket) => {
// listen to send file
ss(socket).on('send-mail', (stream, data) => {
console.log(`*** Begin receive file`);
var writer = fs.createWriteStream(downloadPath, {flags: 'a'});
stream.pipe(writer);
var size = 0;
stream.on('data', (chunk) => {
size += chunk.length;
console.log(`*** Receive ${size} from mail`);
});
stream.on('end', () => {
console.log(`*** End file`);
});
stream.on('error', (error) => {
console.log(`*** Error when receiving file`);
console.log(error);
});
});
});
It works fine, but when transferring file if the second node server is stopped, the app in the other server crashed and an unhandled error event was thrown
Please can anyone tell me how can I catch this error? And if there is a better way to transfer files between node servers?
The text was updated successfully, but these errors were encountered:
I am using socket.io-stream library to transfer files between 2 node servers.
Server A: (Send File)
Server B: (Receive File)
It works fine, but when transferring file if the second node server is stopped, the app in the other server crashed and an unhandled error event was thrown
Please can anyone tell me how can I catch this error? And if there is a better way to transfer files between node servers?
The text was updated successfully, but these errors were encountered: