1

これは、サーバー送信イベント用の ASP.NET です。

Response.ContentType = "text/event-stream";
Response.CacheControl = "no-cache";
//repeat loop
while (true) {
int LastEventId = Request.Headers.Get("Last-Event-ID") != null ?       
Int32.Parse(Request.Headers.Get("Last-Event-ID")) : -1;
int MessageCount =    UserManager.GetMessageCount(UserManager.GetUserDetails(Page.User.Identity.Name).UserId);
if (LastEventId != MessageCount)
{
    Response.Write(string.Format("retry: 5000\nid: {0}\ndata: {0}\n\n", MessageCount));
    Response.Flush();
}
else
{
    Response.Write(string.Format("retry: 5000\nid: {0}\ndata: \n\n", MessageCount));
    Response.Flush();
}
    if (Response.IsClientConnected == false)
{
    break;
}
    Response.Close();
    System.Threading.Thread.Sleep(5000);
}

Firefox ブラウザが 2 回再接続しない。同じコードが Google Chrome で動作しています。誰でもこれで私を助けることができますか?

4

1 に答える 1