Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 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
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Probably you may want to test the Push technology (to let the server send data instead of forcing a refresh from the client side)

    http://en.wikipedia.org/wiki/Push_technology
    http://today.java.net/article/2010/0...ologies-part-1
    http://stackoverflow.com/questions/1...cket-for-html5
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,373
    Thanks
    11
    Thanked 592 Times in 572 Posts
    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...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #4
    Regular Coder
    Join Date
    Mar 2008
    Location
    London
    Posts
    152
    Thanks
    4
    Thanked 42 Times in 42 Posts
    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; 09-12-2011 at 07:05 PM.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •