How do server-sent events work with ASP.NET MVC?

前端 未结 1 517
难免孤独
难免孤独 2021-02-06 16:17

I have an ASP.NET MVC application and I am using server-sent events. The application works fine but I am having some questions on how it works. Below is the controller code.

1条回答
  •  花落未央
    2021-02-06 17:18

    The time gets updated only every 3 seconds. Why is it so?

    Because your Controller is returning the ActionResult containing a single data and then closing the connection, so the browser waits 3 seconds and then re-opens it.

    How to determine how often the controller action will be called?

    The same way you would determine how often any other method will be called, with loops and delays.

    SSE is Server Sent Events, you manage all this stuff from the server side, it'll only work properly if you explicitly hold the connection open, otherwise you may as well do AJAX polling from the client instead.

    0 讨论(0)
提交回复
热议问题