Hi all.
I'm still working on an edonkey clone. Till now everything works fine but in the last weeks I found out that the receiving and send of datas through the network is not so easy as it look on the first view.
I wrote two procedures which should send and receive a string till it is complete. It works - SOMETIMES.
If I send some long Datastrings to the local host server I loose Data and I dont know why.
Here are my two procedures I wote:
Code: Select all
Procedure send(id,txt$)
; calculate bufferlength
length=Len(txt$)+2 ; String + EOL
length+4 ; Packet "length"-Long at beginning
*mem.l=AllocateMemory(0,length,0) ; Allocate our memory
PokeL(*mem.l,length) ; Store the length of our Datapacket
PokeS(*mem.l+4,txt$) ; Now Store the string
send_(id,*mem.l,length,0) ; Send it to our client
FreeMemory(0) ; Free the memory again
EndProcedure
Procedure receive(id)
*mem.l=AllocateMemory(0,4,0) ; alloc 4 Bytes of memory for our header
re=recv_(id,*mem.l,4,0) ; Read our headers first 4 bytes
packetsize.l=PeekL(*mem.l) ; Get our Packetsize length
length=packetsize.l-4 ; -4 couse we still have the header
FreeMemory(0) ; Free our 4 Bytes again
*mem.l=AllocateMemory(0,length,0) ; Allocate the mem for the needed rest
Repeat ; Read ALL our Datas till its complete
re=recv_(id,*mem.l,length,0) ; Read the RAW Datas and count received bytes in re
received+re ; Received charts + re
Until received=length ; Till we have all our datas complete
ProcedureReturn *mem.l ; Return the memory address of our datas
EndProcedure
txt$=peeks(*mem.l) ; To get the String we want
freememory(0) ; Free its memory again
for n=0 to 1000:send(serverID,"blblabla this is a test text"):next n
You will see that not all datas are received on the other side. And now, I want to know why!
Please help me stupid guy. *fg*
Cheers
Mike
Tranquilizer/ Secretly!
Registred PureBasic User
