简体   繁体   中英

How to send the 'FIN' with node.js?

Update: I posted this code here, after I added all (to 99%) possibilities one by one, and it still gave me a 120sec timeout...buffled.


So, ok, I figured it takes exactly 120sec (ok, 122sec) on my Windows 7 machine, until the FIN handshake is started. I want to do it immediately. HTTP RFC793 says

FIN: No more data from sender

Looks to me I do not send any data anymore. I tried all this bloated code, still a Hello World server...

var http = require('http')
var server = http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'})
    res.write('HELLO WORLD!\n')
    res.end()
    res.setTimeout(0)
    req.abort()     // 1) TypeError: Object #<IncomingMessage> has no method 'abort'

    req.on('socket', function (socket) {
        socket.setTimeout(0)  
        socket.on('timeout', function() {
            req.abort()
        })
    })
})
server.timeout = 0
server.setTimeout(0)
server.listen(1337, '192.168.0.101')
  1. So how to do 1) ? (Actually sends a RST like this...)
  2. And how to do the whole thing HTTP conform?
    Of course in the end I will be lucky to use nodejs as in websocket stuff and all this, but if conversion on my website means a thing of two minutes, and I have a million concurrent users (huh?), sending a FIN immediately could mean I have two million concurrent users (do the math). ;) Ok, to be on the sure side: Sending a FIN means the socket is closed?

  3. Ah, eah, ok, since you are on, how do I console.log(res) or console.log(req) ? It gives me [object Object] . (Update: I tried console.log(res.toSource()) , gives me a TypeError ?
    Edit: Found the answer here .

If you want to close the connection, send a connection: close header. If you do this, then it will not leave the connection open for reuse.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM