简体   繁体   English

如何使用node.js发送“ FIN”?

[英]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. 更新:我在此代码中逐一添加了所有(到99%)的可能性之后,在这里发布了此代码,但它仍然给了我120秒的超时时间……...住了。


So, ok, I figured it takes exactly 120sec (ok, 122sec) on my Windows 7 machine, until the FIN handshake is started. 因此,好吧,我发现在Windows 7计算机上,要开始FIN握手之前,它只需要120秒(好,就是122秒)。 I want to do it immediately. 我要立即做。 HTTP RFC793 says HTTP RFC793

FIN: No more data from sender FIN:没有来自发件人的更多数据

Looks to me I do not send any data anymore. 在我看来,我不再发送任何数据。 I tried all this bloated code, still a Hello World server... 我尝试了所有这些肿的代码,仍然是Hello World服务器...

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) ? 那么如何做1)? (Actually sends a RST like this...) (实际上发送这样的RST ...)
  2. And how to do the whole thing HTTP conform? 以及如何使整个HTTP符合要求?
    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). 当然,最后我会很幸运地在websocket内容中使用nodejs ,但如果在我的网站上进行转换意味着两分钟的时间,并且我有100万并发用户(呵呵),立即发送FIN可能表示我有200万并发用户(进行数学计算)。 ;) Ok, to be on the sure side: Sending a FIN means the socket is closed? ;)好的,可以肯定的是:发送FIN表示套接字已关闭?

  3. Ah, eah, ok, since you are on, how do I console.log(res) or console.log(req) ? 嗯,嗯,好的,既然您打开了,我该如何console.log(res)console.log(req) It gives me [object Object] . 它给了我[object Object] (Update: I tried console.log(res.toSource()) , gives me a TypeError ? (更新:我尝试console.log(res.toSource()) ,给我TypeError吗?
    Edit: Found the answer here . 编辑:这里找到答案。

If you want to close the connection, send a connection: close header. 如果要关闭连接,请发送一个connection: close标头。 If you do this, then it will not leave the connection open for reuse. 如果执行此操作,则它将不会保持连接打开以供重用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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