node-tftp icon indicating copy to clipboard operation
node-tftp copied to clipboard

How to end the connection?

Open dkrebs opened this issue 10 years ago • 5 comments

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();

dkrebs avatar Feb 11 '15 13:02 dkrebs

:+1:

TooTallNate avatar Jul 22 '15 07:07 TooTallNate

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?

somecallmemike avatar Feb 29 '16 16:02 somecallmemike

Bueller?

somecallmemike avatar Mar 01 '16 21:03 somecallmemike

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.

Monitor343 avatar Apr 22 '16 12:04 Monitor343

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

michau-krakow avatar Feb 23 '23 19:02 michau-krakow