looping web method until data is found and then return from web service for chat application in asp.net
I have to implement gmail style chatting in my asp.net website. now i know much has been said in this regard here and other forums...about COMET and its befits....
i recently saw this site www.indyarocks.com and when i profiled their website i found out that for chatting they send a async request and the page waits until the server has some data to return and only after the page returns....(i mean it shows status 200 OK) and again a request is dispatched.
i have implemeted chat in my website in which i poll the database after 5 sec for any new chat...so i want to know if i send a request using ASP.NET AJAX to a web method and keep on looping on the server until it has some data to return and then return to the webpage that called it is it a good approach and if not what are its demerits????
the code that i can use
<WebMethod(EnableSession:=True)> _
Public Function looper(ByVal x As String) As String
Dim flag As Boolean = False
While (flag = False)
Dim ans As String = getScalar("select 1 from Chat where sent_by=1")
If Not ans Is Nothing The开发者_运维问答n
flag = True
End If
End While
Return "x"
End Function
here i can loop over the server until it has some data
in any case is it better than the polling approach????
Does anyone have suggestions to improve this approach???
Its better than polling approach from client side
Why, because
- It avoids server roundtrip - saves lot of time
- And avoid unnessary calls to server (Polling approach calls the webmethod even though the data is not available)
In other hand, your current COMET approach, Server calls are minimal from javascript because the new request only be made from client if the server return the updated data.
So keep up with the current design
精彩评论