How to consistently transfer a lot of data through the Socket.io?

From the server side is the SQL query, the result is a lot of data. On average 15K lines. After this piece of rows sorted by date, where the date the array key and value of each - the list of objects on that date. I.e. something like:

points[row.time_update] = [ {val1: 1, val2: 123, val6:321}, {val1: 21, val2: 777, val6:2} ... ]

I.e., the solution to the problem via a limit\offset I channel. What's the problem:

on the client side, the code hangs (the code is rough everywhere, but it reflects the essence):
socket.on('update_recv', function(data) { 
console.log(data);
});


server hangs like this:
socket.on('update', function(data){ 
 knex(sql .... ).then(function(rows){
 // processed line, collect the points array in the required format. 

 var keys = Object.keys(points); // need to issue a batch by date
 for( var k in keys )
{
 // here begins my unknown magic. If bryaknut after socket.emit
 // the data arrives. ie 1 time. otherwise, the cycle goes on, but the front
 // nothing comes. 
 socket.emit('update_recv', {result: JSON.stringify(points[keys[k]]) })
 sleep.sleep(3); // need delay until the rough
}
});
});


How do I sequentially with time intervals, transfer a bunch of lines to the front? To transfer one "packet" with subsequent treatment there, is not very reasonable, plus still is not transmitted.
July 9th 19 at 10:44
1 answer
July 9th 19 at 10:46
With mobile phones hard to see, but the data pulled into an economical package
Could you clarify what is meant by economical package? - Ambros commented on July 9th 19 at 10:49
No problem,just announce the exact data type and range
For a start, even as a string you can remove the json to send the numbers, separated by commas, - mercedes commented on July 9th 19 at 10:52
The client - browser, or other node? - mercedes commented on July 9th 19 at 10:55
: the browser - Ambros commented on July 9th 19 at 10:58
And the question above? - mercedes commented on July 9th 19 at 11:01
:
An example of what is to come
{ latitdue: '22.314567',
longitude: '39.105341',
mac_id: '3A14',
battery_level: 68 },
{ latitdue: '22.314935',
longitude: '39.097595',
mac_id: '872',
battery_level: 72 },
{ latitdue: '22.314935',
longitude: '39.097595',
mac_id: '872',
battery_level: 72 } - Ambros commented on July 9th 19 at 11:04
You need to remove the dictionary,just using a comma to write. Destiny system can be replaced by a 64 hexadecimal for example. Can be converted to bytes and compress gzip , the main thing is not to break in the selling process. Depending on the string representations of the byte to be shorter. An important range of values - mercedes commented on July 9th 19 at 11:07
Binary commas are no longer required. - mercedes commented on July 9th 19 at 11:10
I found a sample problem...the problem is with a loop and socket.emit();

i.e. when:

for(var k in keys){

console.log(k);
socket.emit('node_update_recv2', {result: k});
sleep.sleep(3);

}

the console prints k consistently right and to the front came just a 0, without 1,2,3... ie socket.emit() is executed once - Ambros commented on July 9th 19 at 11:13
In the developer console on the client that receives the websocket - mercedes commented on July 9th 19 at 11:16
comes only the first key. other Amity fail. - Ambros commented on July 9th 19 at 11:19
This is a direct console to see where websocket detailing? - mercedes commented on July 9th 19 at 11:22
in the browser console comes object { result : 0 } and all. in the server console moved 0,1,2,3,4 correctly - Ambros commented on July 9th 19 at 11:25
About the console I realized, look at the log responses on the websocket, the breakpoint is never on the client? - mercedes commented on July 9th 19 at 11:28

Find more questions by tags Socket.ioJavaScript