A little TCP problem (reusing streams)...

Blitz3D Forums/Blitz3D Programming/A little TCP problem (reusing streams)...

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

you cannot clear the queue ... not in blitz
you can do something like syncronising between client and server ... send a sync. time within a packet ... then the receiver could see that he is falling back in time.

to avoid that the receiver lay back in time you should always read as many packets are available. They are allready deliverd then and should not hit the performance that much.
[code]
avail = readavail(stream)
while readavail(stream)
readbytes buffer,stream,0,avail
;do whatever you do with the data
wend
[\code]

UDP is fast ... but network through internet is always "slow" , try to submit as few as possible data. There are many possiblitys to lower the data amount that has to be submited ... interpolate the position and orientations between submissions to get smooth movement with low bandwidth. Do not send the data each frame ! Just send it 10 times per sec. or something like that, maybe you can link that to the ping value or bandwith avail.
Try to make the packets as small as you can ... a hint:
position and orientation is the most needed information but you must not always send the absolut position, you could just send the difference between the last position, then ervery sec. or 2 sec. do a correction and send the full position. This shrinks data very much !
Take a look in the code Archive .. there is a example on how to use cubic interpolation to fight lags.

--- edit -----
another idea: you dont have to submit a orientation as a full float ! Use a short instead or even a single byte will look good in figthing action .. then every degree is is not a fraction of 360 ... but a fraction of 256 (can't explain that easily, but i think you will get it)