socket.io gets Disconnected
dsouzaedison opened this issue · 2 comments
dsouzaedison commented
Server to Server Communication issue (#20)
Receiver Node LOG
Connected to Server socket.
File 0.jpg saved
File 1.jpg saved
File 2.jpg saved
TypeError: Cannot read property 'uid' of null
at Array.<anonymous> (C:\xampp\htdocs\iothss\git-iothss\iothss\node_modules\
delivery\lib\delivery.server.js:124:42)
at PubSub.publish (C:\xampp\htdocs\iothss\git-iothss\iothss\node_modules\del
ivery\lib\delivery.server.js:27:11)
at Socket.<anonymous> (C:\xampp\htdocs\iothss\git-iothss\iothss\node_modules
\delivery\lib\delivery.server.js:155:18)
at Socket.emit (events.js:107:17)
at Socket.onevent (C:\xampp\htdocs\iothss\git-iothss\iothss\node_modules\soc
ket.io\lib\socket.js:335:8)
at Socket.onpacket (C:\xampp\htdocs\iothss\git-iothss\iothss\node_modules\so
cket.io\lib\socket.js:295:12)
at Client.ondecoded (C:\xampp\htdocs\iothss\git-iothss\iothss\node_modules\s
ocket.io\lib\client.js:193:14)
at Decoder.Emitter.emit (C:\xampp\htdocs\iothss\git-iothss\iothss\node_modul
es\socket.io\node_modules\socket.io-parser\node_modules\component-emitter\index.
js:134:20)
at Decoder.add (C:\xampp\htdocs\iothss\git-iothss\iothss\node_modules\socket
.io\node_modules\socket.io-parser\index.js:247:12)
at Client.ondata (C:\xampp\htdocs\iothss\git-iothss\iothss\node_modules\sock
et.io\lib\client.js:175:18)
Socket Disconnected!
File 3.jpg saved
Receive Node Code
function receiveimage(delivery,dir){
delivery.on('receive.success',function(file){
fs.writeFile( __dirname + '/img/' + dir + '/' + file.name, file.buffer, function(err){
if(err){
console.log('File could not be saved: ' + err);
}else{
console.log('File ' + file.name + " saved");
};
});
});
}
Sender Node LOG
Sending Image (1/4)...
Sending Image (2/4)...
Sending Image (3/4)...
Sending Image (4/4)...
-----------------------------------
Images Uploaded Successfully!
Sender Node Code:
function sendimage(delivery,dir){
for(var i=0;i<4;i++) {
console.log( "Sending Image (" + (i+1) + "/4)..." );
delivery.send({
name: i + '.jpg',
path: './img/' + dir + '/' + i + '.jpg'
});
delivery.on('send.success',function(){
console.log("File successfully sent!");
});
}
}
liamks commented
Thanks for reporting this. The code base is pretty small & I accept pull requests!
dsouzaedison commented
Found solution for this problem. Just need to add the following code after attempting to send the images once on sender node server.
socket.disconnect();
socket.connect();
Everything works fine without any problem!