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 ?
AGK network serializor to Purebasic ?
- skinkairewalker
- Enthusiast
- Posts: 627
- Joined: Fri Dec 04, 2015 9:26 pm
Re: AGK network serializor to Purebasic ?
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.
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
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
- skinkairewalker
- Enthusiast
- Posts: 627
- Joined: Fri Dec 04, 2015 9:26 pm
Re: AGK network serializor to Purebasic ?
do you can show me a example how i will get 4 first bytes using ReceiveNetworkData ?
Re: AGK network serializor to Purebasic ?
Code: Select all
len = ReceiveNetworkData(Id, *DataBuffer, 4)
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
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
- skinkairewalker
- Enthusiast
- Posts: 627
- Joined: Fri Dec 04, 2015 9:26 pm
Re: AGK network serializor to Purebasic ?
Awesome <3
you save my life mk-soft
this works fine
thanks you very much !
you save my life mk-soft
this works fine
thanks you very much !
Re: AGK network serializor to Purebasic ?
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
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
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive