NetTalk Central
NetTalk Web Server => Web Server - Ask For Help => Topic started by: Jeffrey Kuijt on February 08, 2012, 10:24:57 AM
-
Hi all,
I use the packet STRING to build a JSON string, but sometimes the JSON string can be very big and the packet string is at that moment too short.
So how can I dynamically return the correct sized packet string?
Should I buy StringTheory for this?
Or can it be done with normal Clarion code? How?
Best regards and thanks
Jeffrey
-
Hi Jeffrey,
Maybe this will help. You are using ParseHTML call to send JSON string in a packet. Since you are using packet variable defined by NT it is limited to 16384 bytes. However, ParseHTML has the following prototype:
ParseHTML PROCEDURE (*String p_Data, long p_DataStart=1, long p_DataEnd=0, Byte p_Header=NET:SendHeader) ,VIRTUAL
which means that it can receive string of any size. Why don't you just create one local variable you use to to build JSON string large enough to receive it and pass it to the ParseHTML call instead of packet var? I think it should not change anything and you will be able to build large JSON string.
Regards,
Alex
-
Thanks Alex,
I thought it would be better to use a dynamic sized string which is possible with StringTheory. So that my string has always the correct size and I don't have the risk that my defined string is too short.
Best regards
Jeffrey
-
Jeffrey,
how about using DynStr interface available in Clarion? Look at DynStr.inc in libsrc directory. You can create new dynamic string, use Cat Method to add to it and CStrRef to post get reference for passing.
Alex
-
Thanks Alex,
Will look at it. 8)
Best regards
Jeffrey
-
>> Since you are using packet variable defined by NT it is limited to 16384 bytes.
not true actually. In sources and browses you can set the length of the variable (see Advanced tab of procedure settings).
>> I thought it would be better to use a dynamic sized string which is possible with StringTheory. So that my string has always the correct size and I don't have the risk that my defined string is too short.
StringTheory will work fine, and has better manipulations than DynStr. for example, in stringtheory it's possible to add all your items to the Linesqueue (see AddLine method) then join them all up together at the end. Prepending and Appending the start and end char is also easier.
>> You are using ParseHTML call to send JSON string in a packet.
Ideally you should rather use the .SendJSON method. this also takes a string of any length.
At the moment it just makes a simple call to _SendMemory, but in the longer run it may get smarter, so calling it for sending JSON text is a good idea for now.
cheers
Bruce
-
Hi Bruce,
StringTheory sounds very good, so I just bought it! ;)
Best regards
Jeffrey
-
Thanks.
Clearly you are an incredibly intelligent person!
-
Ideally you should rather use the .SendJSON method. this also takes a string of any length.
At the moment it just makes a simple call to _SendMemory, but in the longer run it may get smarter, so calling it for sending JSON text is a good idea for now.
Hi Bruce,
Using StringTheory now, very nice, BUT this line generates the error "Syntax error: No matching prototype available" during compiling:
p_web.ParseHTML(st.GetValue(),1,packetlen,Net:NoHeader)
st.GetValue() contains my JSON string.
1. How can I solve this?
2. How can I use the .SendJSON method? What syntax?
Hope you can help me. Can't any further right now
Best regards
Jeffrey
-
So first you ignore my advice, then it doesn't work <g>.
So let's cover the bases;
As Alex pointed out ParseHTML is prototyped as;
ParseHTML PROCEDURE (*String p_Data, long p_DataStart=1, long p_DataEnd=0, Byte p_Header=NET:SendHeader) ,VIRTUAL
Notice that p_data takes a *String, not a String.
st.GetValue() returns a string, not a *string, so you can't use it directly in the line.
what you can do is;
p_web.ParseHTML(st.Value,1,packetlen,Net:NoHeader)
which passes the actual string property to ParseHTML, rather than the result of a method call.
cunningly though SendJSON is prototyped as
NetWebServerWorker.SendJSON Procedure(String p_JSON)
so in this case you can (and I think should) call
p_web.sendJSON(st.GetValue())
cheers
Bruce
-
Thanks Bruce!
I am so glad I bought StringTheory!
Very handy and very powerfull.
Best regards
Jeffrey
-
p_web.sendJSON(st.GetValue())
I get a compile error on the above line:
Field not found: SENDJSON
Unknown procedure label
I am still running with NT5.39.
Could that be the cause?
Best regards
Jeffrey
-
5.39? That's old even by NT5 standards.
yeah, that doesn't have that method. You'll need to use the ParseHTML one.
cheers
Bruce