用node.js創(chuàng)建一個(gè)websocket:javascriptresponse.writeHead(200,{"Content-Type":"text/event-stream"});vartimer=setInterval(function(){varcontent="date:"+newDate().toUTCString()+"\n\n";response.write(content);console.log("Datagotqueuedinmemory(content="+content+")");},1000)由于websocket,需要不斷發(fā)送內(nèi)容,所以不能使用response.end(),但是不執(zhí)行這句話,前端的數(shù)據(jù)就始終在等待狀態(tài).請問有什么辦法能每次response.write()一點(diǎn),前端就接受一點(diǎn),類似于php的@flush()那樣...
使用node.js創(chuàng)建一個(gè)websocket時(shí),不調(diào)用res.end(),客戶端無法顯示數(shù)據(jù)
紫衣仙女
2019-04-07 11:18:44