Click here to Skip to main content
15,845,785 members

Comments by Chopin2001 (Top 77 by date)

Chopin2001 29-May-23 17:54pm View    
However, it is difficult to see that the colors are distorted because of it.
Chopin2001 29-May-23 11:30am View    
I already tried that. The result was the same, only the file size increased.
Thanks
Chopin2001 23-Feb-23 9:16am View    
Deleted
I move the data_header = undefined; line before the socket.send...
Considering the speed difference between server and browser console, it seems to work.
for( let i = -1, max = page_limit['count']; i < max; i++ ){
const imgData = getDataStream(data_header, s_num);
socket.send(imgData)
data_header = undefined;
}
Chopin2001 23-Feb-23 9:03am View    
socket.on('message', function(data){
console.log('client '+data);
});
socket.emit('getData', ...);
I did. But result is same.

I think the problem is inside the for loop.
This is because if you delete all the code in the for loop and run console.log (i++), it works properly.
Chopin2001 23-Feb-23 8:53am View    
It doesn't seem to be a send/message issue.
The code inside the for loop seems to be causing the problem.
The actual code is below.
socket.on('binary', function(data){
	if(data['pID'] == s_num ){
	    for( let i = -1, max = page_limit['count']; i < max; i++ ){
           const imgData = getDataStream(data_header, s_num);
			socket.send(imgData)
			data_header = undefined;		   
        }
    }
});

//get imageheader information
function getDataStream(_data, _num){
    if( _data !== undefined && _data.page == '1' ){
	return readBinary(_data, _num);	
    }else{
	return readBinary(napiFile[_num].getNext(_num), _num); 
    }
}
 
function readBinary(_data, _id){
    var fd = fs.openSync(getPath(_id), 'r');
    if(fd){	
	   var bkgndBuffer = new Buffer.alloc(_data.size);     
	   fs.readSync(fd, bkgndBuffer, 0, _data.size, _data.address);   
	   _data.src = bkgndBuffer.toString('base64');
    }else{
	   return false;
    }
    fs.close(fd);

    return _data;
}
//client
socket.emit('binary', {pID: id});
socket.on('message', function(data){
   MYAPP.Mediator.loadStream(data);
})