Page 11 of 28

Re: HMGSCRIPT 2012: Programming For The Web in The Right Way

Posted: Thu Jun 07, 2012 3:42 am
by Rathinagiri
Hi Roberto,

Have you seen Harbour\source\rtl\hbbit.c which contains the hbbit* functions like hbbit_and() hbbit_or()?

Re: HMGSCRIPT 2012: Programming For The Web in The Right Way

Posted: Thu Jun 07, 2012 12:34 pm
by Roberto Lopez
rathinagiri wrote:Hi Roberto,

Have you seen Harbour\source\rtl\hbbit.c which contains the hbbit* functions like hbbit_and() hbbit_or()?
Thanks.

I've made the same question in the Harbour users forums and Pritpal answered me:
n := hb_bitAnd( n1, hb_bitAnd( n2, n3 ) )
n := hb_bitOr( n1, n2, n3, ..n )

n := hb_bitshift( 1, nBit )
If this works, we will able to send a complete recordset from the server to the client and have data tables (base for grid, browse, etc.).

Re: HMGSCRIPT 2012: Programming For The Web in The Right Way

Posted: Thu Jun 07, 2012 12:57 pm
by Rathinagiri
That's cool.

Now my question is, can we connect to a MySQL database in the local server using websockets if we compile wssocket.exe along with mysql calls and if we have libmysql.dll file in the websocket folder?

Re: HMGSCRIPT 2012: Programming For The Web in The Right Way

Posted: Thu Jun 07, 2012 2:44 pm
by mbelgrano
Here is a more advanced wersion
https://docs.google.com/document/d/1agc ... hvh7c/edit

IMO html websocket will be a important steep for harbour
Chacal.GO wrote:Below another project with sockets (Maybe has something usefull)...

This Project is started at harbour developer group and made from Daniel Garcia Gil e Antonio Linares

You need a HTML5 WebSockets support capable Internet browser like Chrome. Unfortunately IE does not apply. IE is behind its competitors regarding HTML5 support. Thats why I use Chrome, and also because it is much faster. Microsoft has promised a new version with HTML5 support but it seems as it is not ready yet.
Internet Explorer 10 and Metro style apps using JavaScript add support for the WebSocket API as defined in the W3C's HTML5 specification on the WebSocket API, which is currently in the Working Draft stage.
http://code.google.com/p/harbour-websocket/

Re: HMGSCRIPT 2012: Programming For The Web in The Right Way

Posted: Thu Jun 07, 2012 3:29 pm
by Roberto Lopez
rathinagiri wrote:That's cool.

Now my question is, can we connect to a MySQL database in the local server using websockets if we compile wssocket.exe along with mysql calls and if we have libmysql.dll file in the websocket folder?
The server is a Harbour application.

You can do with it, any thing that you can do with Harbour.

The only restriction now is the server to client message length, that is the thing I'm trying to fix.

Re: HMGSCRIPT 2012: Programming For The Web in The Right Way

Posted: Thu Jun 07, 2012 5:28 pm
by Rathinagiri
Ok. :) Super.

Re: HMGSCRIPT 2012: Programming For The Web in The Right Way

Posted: Thu Jun 07, 2012 7:12 pm
by Roberto Lopez
Hi,

I've posted the following message, looking for help, at the Harbour users group.

Any clue about that is welcome:
Hi,

As I've said in a previous post, I'm trying to enhance the Harbour
websockets server by Antonio Linares and Daniel GarcĂ­a Gil to allow it
to return messages longer than 126 bytes to the client browser.

The original line creating data frame is the following:

Code: Select all

oClient:SendData( Chr( 129 ) + Chr( Len( cAnswer ) ) + 
 hb_StrToUtf8( cAnswer ) ) 
I've researched about WebSockets protocol and I've found the following
pseudo-code aimed to explain how data framing must be done:

Code: Select all

////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
 bytesFormatted[0] = 129 

indexStartRawData = -1 // don't matter what value is here; it will be 
 set now: 

if bytesRaw.length <= 125 
     bytesFormatted[1] = bytesRaw.length 

    indexStartRawData = 2 

else if bytesRaw.length >= 126 and bytesRaw.length <= 65535 
     bytesFormatted[1] = 126 
     bytesFormatted[2] = ( bytesRaw.length >> 8 ) AND 255 
     bytesFormatted[3] = ( bytesRaw.length      ) AND 255 

    indexStartRawData = 4 

else 
     bytesFormatted[1] = 127 
     bytesFormatted[2] = ( bytesRaw.length >> 56 ) AND 255 
     bytesFormatted[3] = ( bytesRaw.length >> 48 ) AND 255 
     bytesFormatted[4] = ( bytesRaw.length >> 40 ) AND 255 
     bytesFormatted[5] = ( bytesRaw.length >> 32 ) AND 255 
     bytesFormatted[6] = ( bytesRaw.length >> 24 ) AND 255 
     bytesFormatted[7] = ( bytesRaw.length >> 16 ) AND 255 
     bytesFormatted[8] = ( bytesRaw.length >>  8 ) AND 255 
     bytesFormatted[9] = ( bytesRaw.length       ) AND 255 

    indexStartRawData = 10 

// put raw data at the correct index 
 bytesFormatted.put(bytesRaw, indexStartRawData) 

// now send bytesFormatted (e.g. write it to the socket stream) 
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
Then, I've attempted to translate to Harbour as follows:

Code: Select all

////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 

bytesFormatted_0 := chr(129) 
    if Len( cAnswer ) <= 125 
       bytesFormatted_1 := Chr( Len( cAnswer ) ) 
       oClient:SendData( bytesFormatted_0 + bytesFormatted_1 + 
 hb_StrToUtf8( cAnswer ) ) 
    elseif Len( cAnswer ) >= 126 .and. Len( cAnswer ) <= 65535 
       bytesFormatted_1  := chr(126) 
       bytesFormatted_2  := chr ( hb_bitAnd 
 ( hb_bitShift( Len( cAnswer ) , 8 ) , 255 ) ) 
       bytesFormatted_3  := chr ( hb_bitAnd ( Len( cAnswer ) , 255 ) ) 
                 oClient:SendData( bytesFormatted_0 + bytesFormatted_1 + 
 bytesFormatted_2 + bytesFormatted_3 + hb_StrToUtf8( cAnswer ) ) 
    else 
       /* not implemented yet */ 
    endif 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
But, the code fails to return messages longer than 255 characters.

Is the translation to Harbour correct?

TIA.

Regards,

Roberto.

Re: HMGSCRIPT 2012: Programming For The Web in The Right Way

Posted: Fri Jun 08, 2012 3:55 am
by Roberto Lopez
HMGSCRIPT R010 is Here!

It is able to handle long messages, so we can retrieve recordsets.

There is a new GUI demo showing that.

This was possible with the help of Pritpal and Viktor from the Harbour users forum.

With this enhancement (ability to handle recordsets) the project turned in a feasible way to create web applications using a Harbour server.

I hope that this be useful for you as it is for me, allowing to create mixed environments, where the same dbf files are shared between desktop applications and web applications (local and remote). In my case, for remote Windows clients, I'm using NETIO and for remote web clients I'll use Websockets.

Re: HMGSCRIPT 2012: Programming For The Web in The Right Way

Posted: Fri Jun 08, 2012 4:35 am
by Rathinagiri
Very good Roberto. It is pretty fast enough.

Re: HMGSCRIPT 2012: Programming For The Web in The Right Way

Posted: Fri Jun 08, 2012 4:38 am
by Rathinagiri
Again a basic doubt.

How can we reach the demo.server.html file from another system (say another machine in the same LAN)?