How should I implement the C# server side portion of long-polling for ajax requests? -


i've got architecture involves browsers polling via ajax every 3 seconds updates , i'd change long-polling.

i'd have 1, 2.. {n} clients long-polling, waiting updates , have happen on server signal waiting clients return. first thought use eventwaithandle, , can if want support 1 client. i'd have autoresetevent waithandle waitone block client, maybe timeout, maybe not. either way, autoresetevent allow me support 1 client (since wakes 1 waiting thread) , want n clients.

i'm pretty sure need use manualresetevent waithandle, i'm not sure when call reset after set (when waking threads). should thread.sleep arbitrary amount in between set , reset?

in psuedo code, waking logic

  • get manualreseteventwaithandle
  • call set
  • ensure waiting clients have woken, while preventing new requests blowing through
  • call reset waiting clients have received updates

its 3rd line i'm having hard time with. tossing around idea of having lasttxid client / server maintain , potentially using 2 wait handles. however, before went crazy implementation wanted feedback here see how implement waking logic.

edit: assume i've got problems associated having max concurrent users figured out, either tweaking iis or hosting via wcf or other solution. want focus on waking logic.

one idea, in pseudo code

  • maintain thread-safe list of connection id's, possibly use session id
  • give every connection own autoreseteventwaithandle
  • in thread safe manner, loop through wait handles , set them when there update
  • on session end, in thread safe manner, remove connection / session id list

i'd love feedback on this

con's approach

  • have maintain list of connections
  • have generate {n} wait handles {n} clients

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -