Gunslinger wrote:Hello i have tested this in the SNC in the passed.
That gives me a smile on my face I like if some one test my hobby stuff :-)
Gunslinger wrote:Nicely done. only problem i had is in the function NetworkConnection.GetData(byref pData as any ptr, byval maxSize as integer) as integer
Think it is not the right way to keep waiting or delayed in this function for data to be fully revived or to timeout.
I don't think the same.
You have to use CanGet() and GetData() as a pair and CanPut() and PutData() as pair also !
Compared to no ScreenLock() without an ScreenUnlock() you know what I mean.
Back to GetData() if you used and you schould use CanGet() before there isn't a time out / or big delay while data are reading.
The Timeout value are only used if more data then CHUNK_SIZE (8K) available.
I found out and posted it also, there is no good default CHUNK_SIZE.
On one XP machine 4K chunks was the fasted on my Linux Server 128K and my 4 boxes at home 8 ... 32K
and Raspberry Pi and BeagleBone Black differs also.
The only way to help GetData() to do it best is you as coder knows the maximum size of data chunk you used !
For example if you transmit and received a datastructur of 32 bytes (in a game or anything with a fixed size)
it's a good idea to use the optional parameter maxSize = 32 !
In the latest version of the zip file I wrote:
Code: Select all
if maxSize>0 and maxSize<CHUNK_SIZE then
chunkSize = CHUNK_SIZE ' <-- 8K
dim as integer nBytes = recv(sock,@chunk(0),chunkSize, 0)
On other side if you download videos of 20-40 MB may be changing the const CHUNK SIZE from 8K to 16,32 ... gives a better performance.
The primary problem is (I think) while receiving data
your ISP, Modem, Router, Ethernet card, or WLAN interface doesn't know
how large will it be and you can only give the last device in this chain Ethernet or WLAN device a hint !
(but between your device and the socket interface you are using with "snc.bi" are the software layered stack also)
In real a data frame for DSL, ADSL, VDSL, TCP layer ... can be 1150 bytes or 1280 bytes or 2K ....
But this does not mean you are lucky if you use 1150 bytes or 1280 bytes or 2K also.
The size of a hardware or protocol data chunk isn't pure data it's a header, ckecksums etc. + your data as paiload !
With other words if CanGet() return a "1" there should be no big delay if you call GetData(buffer ptr, maxSize=your_hint) !
By the way you can receive data in a thread code block also.
If you got the data in a buffer you are waiting for set a global flag
(or use the any ptr thread param) for your main code and terminate the thread :-)
Bla bla bla :-)