What is the magic for Lightstreamer?

I am going to develop a structure for comet programming, and I cannot use web sockets or events sent by the server (because browser support really sucks). Thus, I need to keep the HTTP connection alive and send the client data back to the client.

However, problems are manifested in the process:

  • Using XMLHttpRequest is not possible, because IE does not give you xhr.responseText, but xhr.readyState- 3.
  • Hidden iframemay not be useful because the browser shows the loader when I send data back to the client.
  • I tried to send the JavaScript file back to the client, each time sending commands to execute functions, but browsers will not execute JavaScript until they are fully loaded.

However, when I look at the Lightstreamer demo page , I see that it gradually sends the JavaScript file to the client and in each step, it sends a function call and this function just executes (I cannot execute this part). It seems that Lightstreamer uses AJAX, since the request just appears on the Firebug console tab, but it works like a charm in IE.

I tried to use every HTTP header field that they set upon their request, and no result. I also tried using HTTP Post instead of HTTP Get, but did not get any result.

I have read almost 20 articles on how to implement a comet, but none of them can solve the problems that I have:

  • How to do this cross browser?
  • , ( )?
  • ( , )?

- ? , , , . - , ?

+5
4

SockJS .

  • -?

, IE.

  • , ( )?

. , Socket.IO SockJS.

  • ( , )?

, , . - AJAX onload. iframe DOM. .. SockJS Socket.io.

- ? , , , . - , ?

, , . SockJS, Socket.io, faye , .

+5

streaming.

-?

, . . , , , , , . XDomainRequest IE8 +, XMLHttpRequest IE Iframe IE 6+. iframe, .

, ( )?

. , XDomainRequest , XMLHttpRequest readystatechange , Opera IE.

( , )?

iframe, WebKit, Chrome Safari, XMLHttpRequest. - onload , Safari .

, .

  • . .
  • . -.
  • . , . . , , .
  • - Iframe .
  • ...

, , , . , socketio, sockjs jquery socket, .

.

+4

JavaScript .

, <script>? , :

<script type="text/javascript">
f(...data1...);
f(...data2...);

<script type="text/javascript">f(...data1...);</script>
<script type="text/javascript">f(...data2...);</script>
+3
source

The best option in your case would be to use JSONP + Long Pulling on the server side. You just need to remember that you need to reconnect any time when the connection drops (timeout) or you get a response.

Sample code in jquery:

function myJSONP(){
    $.getScript(url, {
        success: function(){
            myJSONP(); //re-connect
        }, 
        failure: function(){
            myJSONP(); //re-connect
        }
    })
} 

Obviously, your response from the server should be javascript code that will call your global functions.

Alternatively, you can use jQuery jQuery.

Or look at this project http://www.meteor.com/ (really cool, but haven't tried it)

+1
source

All Articles