如何关闭服务器上的“服务器发送事件"连接? [英] How to close a "Server-Sent Events"-connection on the server?

查看:62
本文介绍了如何关闭服务器上的“服务器发送事件"连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于本规范:http://www.w3.org/TR/eventsource/

如何关闭服务器上打开的连接?客户端很容易,只需调用close(),但是我应该在服务器上做什么?就杀了它?

How does one close the opened connection on the server? Client-side wise it is easy, just call close(), but what should I do on the server? Just kill it?

推荐答案

node.js:

http.createServer(function (req, res) {

    //...

    // client closes connection
    res.socket.on('close', function () {
      res.end();
      //...
    });

});

见node.js中SSE服务器的实现示例:

see example for implementation of SSE server in node.js:

https://github.com/Yaffle/EventSource/blob/master/nodechat/server.js

这篇关于如何关闭服务器上的“服务器发送事件"连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆