PHP to Harbour

130 views
Skip to first unread message

Roberto Lopez

unread,
Jun 12, 2012, 11:20:00 AM6/12/12
to harbou...@googlegroups.com
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.

Massimo Belgrano

unread,
Jun 12, 2012, 11:32:51 AM6/12/12
to harbou...@googlegroups.com
Good work!
but can be used the upcoming harbour library for serialization by amf?

here Last version hbsocket from daniel if you can't via get svn checkout http://harbour-websocket.googlecode.com/svn/trunk/  


2012/6/12 Roberto Lopez <robe...@gmail.com>

--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users



--
Massimo Belgrano


Roberto Lopez

unread,
Jun 12, 2012, 3:53:32 PM6/12/12
to harbou...@googlegroups.com
On Tuesday, June 12, 2012 12:20:00 PM UTC-3, Roberto Lopez wrote:
Hi,

I still working on some changes to the original WebSockets server by Daniel Garcia Gil and Antonio Linares.


Please, ignore the original post, I've already solved the problem adapting code from Daniel Garcia Gil server current version.

Regards,

Roberto.
Reply all
Reply to author
Forward
0 new messages