Hi Andreas,
Meanwhile, I solved the problem.
It does not matter if you use #RECEIVEBYTES or #RECEIVEALL (untillterm = TRUE), both works.
This code here is an absolute performance killer for large amounts of data:
Code: Select all
part$, c = ReceiveData(ConnectionID, #RECEIVEBYTES, 5)
Answer$ = Answer$ .. part$
The larger the string variable, the slower the program becomes.
Using a Table is much more efficient.
But you should not use the table library, it is just as slow as big string variables!
Here's a working example for other Hollywood programmers.
The server sends messages in the following format: Length of the message followed by the message.
Code: Select all
;SERVER
CreateServer(1,2900)
Function p_ConnectFunc(msg)
Switch(msg.action)
Case "OnDisconnect":
CloseConnection(msg.id)
Case "OnConnect":
For a = 0 To 100000
SendData(msg.clientid,"5Hello")
Next
SendData(msg.clientid,"3end")
EndSwitch
EndFunction
InstallEventHandler({OnConnect = p_ConnectFunc, OnDisconnect = p_ConnectFunc})
Repeat
CheckEvent
Forever
This client uses #RECEIVEBYTES.
Code: Select all
;CLIENT 1
OpenConnection(1, "localhost", 2900)
b$ = {}
c = 0
StartTimer(1)
Repeat
a$ = ReceiveData(1, #RECEIVEBYTES, 1)
a$ = ReceiveData(1, #RECEIVEBYTES, ToNumber(a$))
b$[c] = a$
c = c + 1
Until a$ = "end"
DebugPrint("Needed time: ", GetTimer(1))
DebugPrint("Number of received messages: ", TableItems(b$))
This client uses #RECEIVEALL with untillterm.
Code: Select all
;CLIENT 2
OpenConnection(1, "localhost", 2900)
c$ = {}
Function p_Receive()
Repeat
a$, len = ReceiveData(1, #RECEIVEALL, False)
b$ = b$ .. a$
While StrLen(b$) <> 0
Size = ToNumber(LeftStr(b$, 1))
If StrLen(b$) >= Size + 1
b$ = UnrightStr(b$, 1)
c$[c] = LeftStr(b$, Size)
If c$[c] = "end" Then e = 1
b$ = UnrightStr(b$, Size)
c = c + 1
EndIf
Wend
Until len = 0
EndFunction
InstallEventHandler({OnReceiveData = p_Receive})
StartTimer(1)
While e = 0
CheckEvent
Wend
DebugPrint("Needed time: ", GetTimer(1))
DebugPrint("Number of received messages: ", TableItems(c$))
End
Client 2 with #RECEIVEALL is slightly faster.
However, it only works reliably using Network Events.
Greetings, Michael