AGK network serializor to Purebasic ?

Just starting out? Need help? Post your questions and find answers here.
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 627
Joined: Fri Dec 04, 2015 9:26 pm

AGK network serializor to Purebasic ?

Post by skinkairewalker »

hi everyone !
i would like know how can I represent that in the purebasic using Network Socket?



AGK basic 2 documentation :

" If you are sending the string to a non-AGK app then the string is constructed of a 4 byte length value followed by X bytes of string data where X is the length value. The string is not null terminated "

someone can help me ?
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: AGK network serializor to Purebasic ?

Post by mk-soft »

I think that the length comes first as LONG and then the string.

Therefore, you must first read the first 4 bytes from the ReceiveBuffer and allocate a memory (plus 1 byte null character).
Then read and copy the receive buffer until the number of characters has been received.

Code: Select all

Structure sAKDString
  len.l
  char.a[0] ; Count of chars show len
EndStructure
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 627
Joined: Fri Dec 04, 2015 9:26 pm

Re: AGK network serializor to Purebasic ?

Post by skinkairewalker »

do you can show me a example how i will get 4 first bytes using ReceiveNetworkData ?
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: AGK network serializor to Purebasic ?

Post by mk-soft »

Code: Select all

len = ReceiveNetworkData(Id, *DataBuffer, 4)
Not testet

Edit - Added Timeout

Code: Select all

Procedure.s ReceiveAKD(ClientID)
  Protected len, cnt, size, timeout, error, *Buffer, *AKDSting, result.s
  len = ReceiveNetworkData(ClientID, @AKDStringLen, 4)
  If AKDStringLen
    *AKDSting = AllocateMemory(AKDStringLen + 1)
  Else
    ProcedureReturn ""
  EndIf
  *Buffer = AllocateMemory($FFFF)
  size = $FFFF
  If size > AKDStringLen
    size = AKDStringLen
  EndIf
  Repeat
    len = ReceiveNetworkData(ClientID, *Buffer, size)
    If len > 0
      CopyMemory(*Buffer, *AKDSting + cnt, len)
      cnt + len
      If size > (AKDStringLen - cnt)
        size = (AKDStringLen - cnt)
      EndIf
      timeout = 0
    Else
      Delay(10)
      timeout + 10 ; Millisecond
      If timeout >= 5000
        error = #True ; Communication error
        Break
      EndIf
    EndIf
  Until cnt >= AKDStringLen
  result = PeekS(*AKDSting, -1, #PB_Ascii)
  FreeMemory(*Buffer)
  FreeMemory(*AKDSting)
  ProcedureReturn result
EndProcedure
Last edited by mk-soft on Sun Feb 25, 2018 2:53 pm, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 627
Joined: Fri Dec 04, 2015 9:26 pm

Re: AGK network serializor to Purebasic ?

Post by skinkairewalker »

Awesome <3

you save my life mk-soft

this works fine :D

thanks you very much !
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: AGK network serializor to Purebasic ?

Post by mk-soft »

So the code is not complete.
If it leads to a communication error, the code will hang.
Extended the code with a timeout.

But you should always think about it yourself
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply