我在ASP.NET中有以下SSE处理程序:
但是我没有成功。
Response.ContentType = "text/event-stream";
while (true)
{
Response.Write(string.Format("data: {0}\n\n", DateTime.Now.ToString()));
Response.Flush();
System.Threading.Thread.Sleep(1000);
}
它一直运行,即使我关闭了客户端应用程序。如何通知服务器停止处理程序?
我在客户端尝试过:
var source = new EventSource('Handler.aspx');
window.onunload = function() {
source.close();
}
但是我没有成功。