node-tftp
node-tftp copied to clipboard
How to end the connection?
I'm trying to send a file via the client.put function to a server which I created with the tftp.createServer function. The server is set to allow put requests and saves the file in a directory. So far, everything is working, the file is present at the server and the size seems to be fine.
However, after sending the file, the client always get's a timeout [Error: Timed out] and I can't find any event which allows me to end the helper connection / see if the transfer was successful.
Any ideas? Thank you in advance! :)
Client:
var client = tftp.createClient ({ port: PORT });
client.put(local,function(error) {
console.log('cb');
if (error) console.error (error);
});
Server:
var server = tftp.createServer({
host: HOST,
port: PORT,
root: rootDir,
denyGET: true
});
server.on ("request", function (req, res){
console.log(req.file);
req.on ("error", function (error){
console.error ("[" + req.stats.remoteAddress + ":" + req.stats.remotePort +
"] (" + req.file + ") " + error.message);
});
req.on('end',function(){
console.log('req.close()');
req.close();
});
});
server.on('close',function(){
console.log('closed');
});
server.on ("listening", function(){
console.log('listening');
});
server.listen();
:+1:
I am having the same issue, I don't see a documented method for properly closing the connection. Can we get some clarification on this?
Bueller?
I have been having this same issue with the server. The file gets uploaded in its entirety but the client never gets an OK. I did some packet captures and found that the server is not sending the ACK acknowledging the receipt of the final packet (a data packet smaller than set block size). The client then just re-transmits the last packet to the server until it times out and sends an error to the server.
Unfortunately, I have exhausted my Node.js skills and don't have any suggestions on how this can be fixed in the code.
The problem is that client socket is being closed too soon after file transfer is finished. Socket is closed just after receiving last DATA packet, which means final ACK packet may not have enough time to get sent by the underlying OS functions, so the client may never receive the ACK. As a result, the transfer is successfully finished on server but client would see failure, retransmissions and eventually a timeout. A fix is provided in pull request https://github.com/gagle/node-tftp/pull/29