Server to Server Seems to Send Data Twice.
I'm trying to use your library to do fast server to server file transfers. I've attempted to use your examples.
receiver.js
var io = require('socket.io').listen(5001),
dl = require('delivery'),
fs = require('fs');
io.sockets.on('connection', function(socket){
var delivery = dl.listen(socket);
delivery.on('receive.success',function(file){
fs.writeFile('./data2/' + file.name, file.buffer, function(err){
if (err) {
console.log('File could not be saved.', file.uid, file.name);
} else {
console.log('File saved.', file.uid, file.name);
};
});
});
});
sender.js
var socket = require('socket.io-client')('http://0.0.0.0:5001');
var dl = require('delivery')
var fs = require('fs')
var async = require('async')
socket.on('connect', function(){
var delivery = dl.listen(socket);
delivery.connect()
console.log('----connected----')
delivery.on('delivery.connect',function(delsocket){
console.log('delivery connected')
delsocket.on('send.success',function(fileUID){
console.log("file was successfully sent.", fileUID);
});
fs.readdir('./data1', function(err, files) {
async.eachSeries(files, function(f, cb) {
console.log('called', f)
delivery.send({
name: f,
path: './data1/' + f
})
cb()
})
})
});
});
It seems that the loop only does a "delivery.send" once per file, but the send.success triggers twice per file. I've tried listening on the overall delivery for send.success but also on the delivery.connect event too.
----connected----
delivery connected
called 1425339118.sst
called 1425339126.sst
called 1425339135.sst
called thisisanewfile.txt
file was successfully sent. 863defe2-be89-4d24-a1a7-bbba02b87cc6
file was successfully sent. 863defe2-be89-4d24-a1a7-bbba02b87cc6
file was successfully sent. 772296e5-5e7d-4387-a23e-298dd7dd8829
file was successfully sent. 772296e5-5e7d-4387-a23e-298dd7dd8829
file was successfully sent. d783486d-1b63-42f4-99e0-13ec47cbd8fa
file was successfully sent. d783486d-1b63-42f4-99e0-13ec47cbd8fa
file was successfully sent. e6a36bde-1eb9-4dc8-b7e1-e1f7c98ea6da
file was successfully sent. e6a36bde-1eb9-4dc8-b7e1-e1f7c98ea6da
Thanks.
Okay, that certainly looks odd. I'd recommend debugging the source for Delivery.js. I'd recommend adding some console.log() statements to deliveryJS (within your node_modules folder). Alternatively you can use node inspector and do debugging. Either way I don't see anything immediately off with your code or the source. Let me know if you find anything!
receive.success Event pass more than 4 times for one file procedure. I try small file and large . Results : node send method means split package to more smallest ... Catch last package and after last you can emit receive.success event . Thanks for this plugin it is very simple and usefull .
Have you tested this with v0.0.5? It's possible that this is the same issue as #19, in which case it has been fixed.
Hi! I have the same issue, from client->server with version 0.0.5. The receive.success event is being fired 4 times every time I upload a file (which in turn means my file-write is happening 4 time! :O)
Will try some debugging in a bit, but wanted to bump the post so you guys know there's still an issue.
Actually, it looks like the receive.success is running twice, and the send.success is running twice PER receive.
Can you paste the console output along with your code on sender and receiver?
Sure, here's my code.
Server:
io.on('connection',function(socket){
// File upload begin
var delivery = dl.listen(socket);
delivery.on('receive.success',function(file){
var params = file.params;
console.log(file.name);
// File upload end
});
....
Client:
// Prepping listeners. No longer bothering to try to use send.success
socket.on('connect', function(){
Self.delivery.on('delivery.connect',function(delivery){
Self.deliveryready = true;
});
Self.socket.on('file_uploaded',function(res){
toggleLoad2(true);
if(res){
dropInfo('File uploaded successfully!');
} else { dropInfo('File uploaded failed',{level: 'error'}); }
});
});
...
// Use file-picker to choose file with lots of complicated code here
delivery.send(file, extraParams);
It's not all that complicated an implementation... My server console output always shows any file-names I have twice. Two events are sent back to the client saying the upload was successful as well.
Getting same problem...Any solution?