The optional param maxSize of the GetData() function was missing in "snc.bi".
Download SimpleNetworkConnection.zip again
If you receive any unknow size of data Data
you can fill a buffer while you get any data and interrupt if a timeout happens.
This timeout was the problem every call to GetData() was waiting this timeout delay.
If you receive data and knows it's size
you can fill a buffer while received bytes < dataSize or a timeout happens.
note: Transfering a large block of data in chunks of 8 KB is much faster as a chunk size of for example 256 KB.
You can compare the time if you change DATA_PAKET_SIZE from 1024*8 to 1024*256.
Joshy
Code: Select all
#include once "snc.bi"
const PORT = 12345
const DATA_PAKET_SIZE = 1024*8 ' 8 KB
dim as ubyte ptr pData,pDatapacket = allocate(DATA_PAKET_SIZE)
var t = timer()
var Server = new NetworkServer(PORT)
t=timer()-t
print "time to create a local server: " & t
t=timer()
var Client = new NetworkClient("127.0.0.1",PORT)
t=timer()-t
print "time to create a local client: " & t
t=timer()
var ToClient = Server->getConnection()
t=timer()-t
print "time to get client connection: " & t
t=timer()
var ToServer = Client->getConnection()
t=timer()-t
print "time to get server connection: " & t
print "mensured data tranfer rate"
dim as double tPut,tGet
t=timer()
dim as integer processed,nbytes
while processed < 1024*1024 ' 1 MB
tPut=timer()
nBytes = ToServer->PutData(pDatapacket,DATA_PAKET_SIZE)
tPut=timer()-tPut
print "time to put: " & tPut
tGet=timer()
nBytes=ToClient->GetData(pData,DATA_PAKET_SIZE)
tGet=timer()-tGet
print "time to get: " & tGet
processed+=nBytes
wend
t=timer()-t
print
print "time to send and receive 1 MB in packages of 8 KB : " & t
print "done ..."
delete client
delete server
sleep