服务器端的彗星应用应该是什么代码

时间:2022-02-18 03:58:14

I am working on a chatting application and i was using simple ajax polling to retrieve the new chat but its working good because there are few more xmlHttp request to check online status and to send chat to others and some for other reason, so i think there are many request in my form thats why its not working so now i want to do these things in Comet style. so please tell me about it that how to do.

我正在使用一个聊天应用程序,我正在使用简单的ajax轮询来检索新的聊天,但它的工作正常,因为有更多的xmlHttp请求检查在线状态并发送聊天给其他人和一些其他原因,所以我认为那里我的形式有很多请求,这就是为什么它不工作所以现在我想用Comet风格做这些事情。所以请告诉我这是怎么做的。

this is sever side code

这是服务器端代码

Dim output As String = JavaScriptConvert.SerializeObject(newChat)               
                    Response.Flush()
                    Response.Clear()
                    Response.Write(output)
                    Response.End()

and at client side i was set a time out to check continuously.

在客户端,我有时间不断检查。

2 个解决方案

#1


0  

You do understand what Comet is, right? It means leaving the http connection in a hanging state (as if the download has halted) until the server has something interesting to tell the client.

你明白Comet是什么,对吗?这意味着将http连接保持挂起状态(好像下载已经停止),直到服务器有一些有趣的东西告诉客户端。

The client would not have a timeout. It would simply request again if the current download ends.

客户端不会超时。如果当前下载结束,它将再次请求。

Timeouts might occur on the server to try to pre-empt the network timeouts that might occur in hardware on the route from server to client (proxies etc).

服务器上可能会发生超时,以尝试抢占从服务器到客户端(代理等)的路径上的硬件中可能发生的网络超时。

Writing a Comet server is not a trivial undertaking. It seems you need a better understanding of the concepts before embarking on such a perilous adventure.

编写Comet服务器并非易事。在开始这样一个危险的冒险之前,你似乎需要更好地理解这些概念。

#2


0  

I can't really give a good response to your question because the code you've included so far isn't clear as to the background of what your server is doing. Comet is nice, but its not a panacea, and as mentioned before there are some concepts that you'll need to understand in order to successfully implement.

我无法真正回答你的问题,因为到目前为止你所包含的代码并不清楚你的服务器在做什么的背景。彗星很好,但它不是灵丹妙药,如前所述,为了成功实施,你需要了解一些概念。

I recommend that you be intimately familiar with the page life cycle of an asp.net page, how that life cycle is represented in your client's request object (read xmlhttprequest.readystate,) and how your server.

我建议您非常熟悉asp.net页面的页面生命周期,如何在客户端的请求对象(读取xmlhttprequest.readystate)以及服务器的方式中表示生命周期。

As far as what code you have included, in my experience, calling Response.End() or having an end of the function closes the response which is not necessarily what you want to happen.

至于你所包含的代码,根据我的经验,调用Response.End()或者函数结束会关闭响应,这不一定是你想要发生的。

In a custom server that we use, I use an event wait handle to signal and wait for user input from the client. I also have to make sure that if the user is sending a lot of requests that the data is either packaged and handled at the server correctly, or that those requests don't block the viewstate thread (which handles that output back to the client.)

在我们使用的自定义服务器中,我使用事件等待句柄来发信号并等待来自客户端的用户输入。我还必须确保如果用户发送了大量请求,要求数据在服务器上正确打包和处理,或者这些请求不会阻止视图状态线程(将输出处理回客户端)。 )

I believe, that the least amount of complexity is achieved when you use only two requests. (I believe this is also per specification, but I can't seem to find it atm.)

我相信,当您只使用两个请求时,实现的复杂性最小。 (我相信这也符合规范,但我似乎无法找到它。)

For a good read, check out Comet and Reverse Ajax (available via apress)

如需阅读,请查看Comet和Reverse Ajax(可通过apress获取)

#1


0  

You do understand what Comet is, right? It means leaving the http connection in a hanging state (as if the download has halted) until the server has something interesting to tell the client.

你明白Comet是什么,对吗?这意味着将http连接保持挂起状态(好像下载已经停止),直到服务器有一些有趣的东西告诉客户端。

The client would not have a timeout. It would simply request again if the current download ends.

客户端不会超时。如果当前下载结束,它将再次请求。

Timeouts might occur on the server to try to pre-empt the network timeouts that might occur in hardware on the route from server to client (proxies etc).

服务器上可能会发生超时,以尝试抢占从服务器到客户端(代理等)的路径上的硬件中可能发生的网络超时。

Writing a Comet server is not a trivial undertaking. It seems you need a better understanding of the concepts before embarking on such a perilous adventure.

编写Comet服务器并非易事。在开始这样一个危险的冒险之前,你似乎需要更好地理解这些概念。

#2


0  

I can't really give a good response to your question because the code you've included so far isn't clear as to the background of what your server is doing. Comet is nice, but its not a panacea, and as mentioned before there are some concepts that you'll need to understand in order to successfully implement.

我无法真正回答你的问题,因为到目前为止你所包含的代码并不清楚你的服务器在做什么的背景。彗星很好,但它不是灵丹妙药,如前所述,为了成功实施,你需要了解一些概念。

I recommend that you be intimately familiar with the page life cycle of an asp.net page, how that life cycle is represented in your client's request object (read xmlhttprequest.readystate,) and how your server.

我建议您非常熟悉asp.net页面的页面生命周期,如何在客户端的请求对象(读取xmlhttprequest.readystate)以及服务器的方式中表示生命周期。

As far as what code you have included, in my experience, calling Response.End() or having an end of the function closes the response which is not necessarily what you want to happen.

至于你所包含的代码,根据我的经验,调用Response.End()或者函数结束会关闭响应,这不一定是你想要发生的。

In a custom server that we use, I use an event wait handle to signal and wait for user input from the client. I also have to make sure that if the user is sending a lot of requests that the data is either packaged and handled at the server correctly, or that those requests don't block the viewstate thread (which handles that output back to the client.)

在我们使用的自定义服务器中,我使用事件等待句柄来发信号并等待来自客户端的用户输入。我还必须确保如果用户发送了大量请求,要求数据在服务器上正确打包和处理,或者这些请求不会阻止视图状态线程(将输出处理回客户端)。 )

I believe, that the least amount of complexity is achieved when you use only two requests. (I believe this is also per specification, but I can't seem to find it atm.)

我相信,当您只使用两个请求时,实现的复杂性最小。 (我相信这也符合规范,但我似乎无法找到它。)

For a good read, check out Comet and Reverse Ajax (available via apress)

如需阅读,请查看Comet和Reverse Ajax(可通过apress获取)