是否有可能刷新对客户端的节点响应以使连接保持活动状态? [英] Is it possible to flush a node response to the client to keep a connection alive?

查看:68
本文介绍了是否有可能刷新对客户端的节点响应以使连接保持活动状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户端正在请求的大型数据集.它需要加载和处理,因此我可以将其转换为CSV.如果我尝试一次加载并转换整个数据集,则在客户端超时之前它不会完成处理.响应于此,我加载了数据集,然后将其分块进行处理.此时,我已经准备好在超时之前将数据发送到客户端

I have a large data-set that a client is requesting. It requires loading and processing so I can convert it to CSV. If I try to load and convert the entire data-set at once it doesn't finish processing before the client times out. In response to this, I load my data-set and then chunk it for processing. At this point I have data ready to send to the client before the timeout.

我的问题是,当我通过将写流传输到响应中或通过侦听我的写流并发送VIA response.write来发送数据时,它无法及时发送.这似乎是因为我没有在响应编写器上达到highWaterMark.我需要一种方法来告诉连接等待更长的时间(res.setTimeout(2147483647);似乎不能解决问题),降低highWaterMark或耗尽响应,以便客户端在传入数据时始终获得已处理的数据.

My issue is that when I send the data, either by piping my write stream into the response, or by listening to my write stream and sending VIA response.write, it does not get sent in time. This seems to be because I'm not hitting the highWaterMark on the response writer. I need a way to either tell the connection to wait longer (res.setTimeout(2147483647); doesn't seem to do the trick), lower the highWaterMark, or to drain the response so the client consistently gets the processed data as it comes in.

这是在具有Express 4的节点12.x上.

This is on Node 12.x w/ Express 4.

推荐答案

Is it possible to flush a node response to the client to keep a connection alive? As per what jfriend00 said, corking my response before writing data, writing the data, and then uncorking it caused it to be sent to the client.

称此解决.

这篇关于是否有可能刷新对客户端的节点响应以使连接保持活动状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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