Web Analytics Made Easy -
StatCounter how to read streaming data in javascript - CodingForum

Announcement

Collapse
No announcement yet.

how to read streaming data in javascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to read streaming data in javascript

    I wants to access server web page which data is continuously growing(streaming data), I want to buffered some of that data write it in responseText then again get next buffered data write it and so on (in AJAX).
    Is it possible? if yes how to do that?

  • #2
    Probably you may want to test the Push technology (to let the server send data instead of forcing a refresh from the client side)



    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

    Comment


    • #3
      sure, just don't close the http connection on the server and both ajax and <script src="xxx"/> loads will wait until the connection is closed before parsing or firing onreadystatechange with a complete status...
      Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

      Comment


      • #4
        below is the sample code that might give you an idea of implementing your requirements.
        its just a thought, and not a working model.
        Code:
        var start_index = 0;
        var buffer_size = 1000;
        var end_of_file = false;
        var server_url = 'your_server_url_goes_here';
        
        function getDataFromServer_AJAX(server_url, start_index, buffer_size, callBackFunction) {
        	if(!end_of_file) {
        		// add your AJAX call to server here, with start_index and buffer_size passed as a parameter
        		// define your desired reponse format. I have used following format -
        		/*
        			response = {'status': 0, 'data': 'No data found / end of file' }
        			response = {'status': 1, 'data': 'my data string extracted from the stream' }
        			// you can add more response status codes as per need
        		*/
        		callBackFunction(response);
        	}
        }
        
        function callBackFunction(response) {
        	if(response != null && response.status == 1) { // required data has been found
        		var data = response.data;
        		// process your data
        		// .........
        		// .........
        		// at the end, update the indexes 
        		start_index += data.length + 1;
        	}
        	else {
        		// no data found, end of file etc
        		end_of_file = true;
        	}
        	// continue streaming the data
        	getDataFromServer_AJAX(server_url, start_index, buffer_size, callBackFunction);
        }
        Hope it may help you out..

        Thanks & Regards,
        Niral Soni
        Last edited by WA; Sep 12, 2011, 02:05 PM.

        Comment

        Working...
        X
        😀
        🥰
        🤢
        😎
        😡
        👍
        👎