什么是背后Lightstreamer的魔力?魔力、Lightstreamer

2023-09-10 19:15:52 作者:半粒小葡萄

我会制定彗星编程框架,我不能使用网络套接字,或服务器发送的事件(因为浏览器的支持真的很烂)。所以,我需要保持HTTP连接活着,并发送分块的数据返回给客户端。

I'm gonna develop a framework for comet programming, and I can't use Web Sockets, or Server-Sent Events (because browser support really sucks). So, I need to keep the HTTP connection alive, and send chunked data back to the client.

然而,问题展示自己,因为你进入工作:

However, problems show themselves as you get into the work:

使用XMLHtt prequest是不可能的,因为事实上,IE浏览器不给你 xhr.responseText ,而 XHR。 readyState的 3。 在一个隐藏的 IFRAME 不能是有用的,因为浏览器将显示加载器,而我将数据发送回客户端。 我试图发送一个JavaScript文件返回给客户端,每次发送功能执行命令,但浏览器不会执行JavaScript,直到它完全加载。 Using XMLHttpRequest is not possible, due to the fact that IE doesn't give you xhr.responseText while the xhr.readyState is 3. A hidden iframe can't be useful, because browser shows the loader while I send data back to the client. I tried to send a JavaScript file back to the client, sending function execution commands each time, but browsers won't execute JavaScript till it's completely loaded.

不过,当我看着 Lightstreamer演示页,我看到它发送一个JavaScript文件返回给客户端一点一点地在每一个步骤,它发送一个呼叫的功能,该功能只是被执行(我不能做到这一点的一部分)。看来,Lightstreamer使用AJAX,因为请求只是显示在Firebug的控制台选项卡,但它的工作原理就像在IE浏览器的魅力了。

However, when I look at Lightstreamer demo page, I see that it sends a JavaScript file back to the client little by little and in each step, it sends a call to the function and that function simply gets executed (I can't do this part). It seems that Lightstreamer uses AJAX, since the request simply shows up in Firebug's console tab, but it works like a charm in IE too.

我试图用每一个HTTP头字段,他们已经对自己的要求设置,并没有结果。我也尝试使用HTTP发布,而不是HTTP GET,但仍没有得到结果。

I tried to use every HTTP header field they've set on their request, and no result. I also tried to use HTTP Post instead of HTTP Get, but still got no result.

我读过近20余篇关于如何实现彗星,但没有of'em出现来解决问题,我有:

I've read almost over 20 articles on how to implement comet, but none of'em appear to solve problems I have:

如何使跨浏览器? 当新的数据从服务器到(我应该勾成什么事件)?如何获得通知 如何使我的页面均显示为完全加载到用户(如何实现它,从而使浏览器不显示加载活动)?

任何人都可以请帮助?我觉得应该有一个非常小的技巧和窍门,我不知道这里粘上所有的概念放在一起。有谁知道lightstreamer做才能克服这些问题?

Can anyone please help? I think there should be a very little tip or trick that I don't know here to glue all the concepts together. Does anyone know what lightstreamer do to overcome these problems?

推荐答案

SockJS这里笔者。

SockJS author here.

  如何使跨浏览器?   

这是很难的,预计要花几个月就获得流媒体传输的歌剧和IE浏览器。

This is hard, expect to spend a few months on getting streaming transports on opera and IE.

  当新的数据从服务器到(我应该勾成什么事件)?如何获得通知   

有各种技术,这取决于一个特定的浏览器。对于一个很好的介绍看看通过Socket.IO和SockJS支持不同的回退协议。

There are various techniques, depending on a particular browser. For a good intro take a look at different fallback protocols supported by Socket.IO and SockJS.

  如何使我的页面均显示为完全加载到用户(如何实现它,从而使浏览器不显示加载活动)?   

此外,还有浏览器特定的技巧。一个是onload事件后延迟加载AJAX。其他是绑定和 - 解除绑定DOM一个iframe。等等。如果你还觉得有兴趣读SockJS或Socket.io code。

Again, there are browser-specific tricks. One is to delay loading AJAX after onload event. Other is to bind-and-unbind an iframe from DOM. ETC. If you still feel interested read SockJS or Socket.io code.

任何人都可以请帮助?我觉得应该有一个非常小的技巧和窍门,我不知道这里粘上所有的概念放在一起。有谁知道lightstreamer做才能克服这些问题?

Can anyone please help? I think there should be a very little tip or trick that I don't know here to glue all the concepts together. Does anyone know what lightstreamer do to overcome these problems?

基本上,除非你有一个非常强有​​力的理由,不要重新发明轮子。使用SockJS,Socket.io,王菲,或任何其他的几十个项目就解决这个问题了。

Basically, unless you have a very strong reason to, don't reinvent the wheel. Use SockJS, Socket.io, faye, or any other of dozens projects that do solve this problem already.