NetTalk Central

Author Topic: Return DYNAMIC packet string - How?  (Read 9825 times)

Jeffrey Kuijt

  • Full Member
  • ***
  • Posts: 142
    • View Profile
    • Email
Return DYNAMIC packet string - How?
« 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

alex.kolaric

  • Full Member
  • ***
  • Posts: 151
  • Do it or do not, there is no try
    • View Profile
    • Email
Re: Return DYNAMIC packet string - How?
« Reply #1 on: February 08, 2012, 11:34:19 AM »
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

Jeffrey Kuijt

  • Full Member
  • ***
  • Posts: 142
    • View Profile
    • Email
Re: Return DYNAMIC packet string - How?
« Reply #2 on: February 08, 2012, 11:50:30 AM »
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

alex.kolaric

  • Full Member
  • ***
  • Posts: 151
  • Do it or do not, there is no try
    • View Profile
    • Email
Re: Return DYNAMIC packet string - How?
« Reply #3 on: February 08, 2012, 12:14:07 PM »
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


Jeffrey Kuijt

  • Full Member
  • ***
  • Posts: 142
    • View Profile
    • Email
Re: Return DYNAMIC packet string - How?
« Reply #4 on: February 08, 2012, 12:21:19 PM »
Thanks Alex,

Will look at it.  8)

Best regards
Jeffrey

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Return DYNAMIC packet string - How?
« Reply #5 on: February 08, 2012, 09:49:20 PM »
>> 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


Jeffrey Kuijt

  • Full Member
  • ***
  • Posts: 142
    • View Profile
    • Email
Re: Return DYNAMIC packet string - How?
« Reply #6 on: February 08, 2012, 11:45:02 PM »
Hi Bruce,

StringTheory sounds very good, so I just bought it!  ;)

Best regards
Jeffrey

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Return DYNAMIC packet string - How?
« Reply #7 on: February 09, 2012, 12:22:48 AM »
Thanks.
Clearly you are an incredibly intelligent person!

Jeffrey Kuijt

  • Full Member
  • ***
  • Posts: 142
    • View Profile
    • Email
Re: Return DYNAMIC packet string - How?
« Reply #8 on: February 09, 2012, 02:33:40 AM »
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

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Return DYNAMIC packet string - How?
« Reply #9 on: February 09, 2012, 07:54:23 AM »
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

Jeffrey Kuijt

  • Full Member
  • ***
  • Posts: 142
    • View Profile
    • Email
Re: Return DYNAMIC packet string - How?
« Reply #10 on: February 09, 2012, 10:57:28 AM »
Thanks Bruce!

I am so glad I bought StringTheory!
Very handy and very powerfull.

Best regards
Jeffrey

Jeffrey Kuijt

  • Full Member
  • ***
  • Posts: 142
    • View Profile
    • Email
Re: Return DYNAMIC packet string - How?
« Reply #11 on: February 10, 2012, 04:52:29 AM »

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

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Return DYNAMIC packet string - How?
« Reply #12 on: February 10, 2012, 07:35:26 AM »
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