Hi,
I still working on some changes to the original WebSockets server by Daniel Garcia Gil and Antonio Linares.
There is a limitation regarding the amount of data that the server is capable to read in a single message from client (about 125 bytes)..
I've found a PHP function capable to decode messages
of any size
from client. I've ported to Harbour and it 'almost' work.
Decoding fails every four bytes, ie:
This message...
Query([test],{[code],
Is translated to:
QueLy([Jestc,{[]odec,
I'm obviously missing something.
Here is the PHP original code and my Harbour port.
Any help is welcome:
///////// PHP CODE /////////////////
$bytes = $data;
$data_length = "";
$mask = "";
$coded_data = "" ;
$decoded_data = "";
$data_length = $bytes[1] & 127;
if($data_length === 126){
$mask = substr($bytes, 4, 8);
$coded_data = substr($bytes, 8);
}else if($data_length === 127){
$mask = substr($bytes, 10, 14);
$coded_data = substr($bytes, 14);
}else{
$mask = substr($bytes, 2, 6);
$coded_data = substr($bytes, 6);
}
for($i=0;$i<strlen($coded_data);$i++){
$decoded_data .= $coded_data[$i] ^ $mask[$i%4];
}
///////// END OF PHP CODE /////////////////////
//////////// START OF HARBOUR CODE ///////////////////
bytes := oClient:cBuffer
data_length := 0
mask := ""
coded_data := ""
decoded_data := ""
data_length = hb_bitAnd ( ASC ( substr(bytes,2,1) ) , 127 )
if data_length == 126
mask := substr( bytes, 5, 8)
coded_data = substr( bytes, 9, len(bytes) )
elseif data_length == 127
mask = substr( bytes, 11 , 14 )
coded_data = substr( bytes , 15 , len(bytes) )
else
mask = substr ( bytes, 3, 6 )
coded_data = substr( bytes, 7 , len(bytes) )
endif
for i := 1 to len( coded_data )
decoded_data += chr ( hb_bitXor ( ASC(substr(coded_data , i , 1 ) ) , ASC(substr ( mask , mod(i , 4 ), 1 ) ) ) )
next i
//////////// END OF HARBOUR CODE ///////////////////
Regards,
Roberto.