Thanks for posting those code snippets. I can confirm the behaviour here. That's not how it should behave. I'll fix this so that #RECEIVEBYTES returns immediately as soon as there is no more data, as documented.msu wrote: ↑Mon Apr 22, 2019 9:23 pm Here's an example:
Server:Code: Select all
CreateServer(1,2900) Function p_ConnectFunc(msg) Switch(msg.action) Case "OnDisconnect": CloseConnection(msg.id) Case "OnConnect": SendData(msg.clientid,"Hallo Klient") EndSwitch EndFunction InstallEventHandler({OnConnect = p_ConnectFunc, OnDisconnect = p_ConnectFunc}) Repeat CheckEvent Forever
Client:The client displays the message after 10 seconds (NetworkTimeout default).Code: Select all
OpenConnection(1, "localhost", 2900) a$ = ReceiveData(1, #RECEIVEBYTES, 200) NPrint(a$) WaitLeftMouse
Exactly the same behavior as with the database server.
Problem with ReceiveData
- airsoftsoftwair
- Posts: 5443
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Problem with ReceiveData
Re: Problem with ReceiveData
Thank you!
PostgreSQL-Library V1.0 Final: https://forum.amiga-resistance.info/vie ... =38&t=3591
- airsoftsoftwair
- Posts: 5443
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Problem with ReceiveData
I've taken a closer look now what's going on under the hood here and I can confirm that #RECEIVEBYTES indeed will always block until the timeout has occurred if there's not enough data in the queue.
However, you might get what you want by using #RECEIVEALL and setting its untilterm argument to FALSE. This should be a way to receive everything that is currently in the queue without any blocking, e.g. do the following:
Does that solve the problem now?
However, you might get what you want by using #RECEIVEALL and setting its untilterm argument to FALSE. This should be a way to receive everything that is currently in the queue without any blocking, e.g. do the following:
Code: Select all
a$, len = ReceiveData(1, #RECEIVEALL, False)
; now check "len" to see how many bytes you've got and call #RECEIVEALL again if you need more data
Re: Problem with ReceiveData
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:
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.
This client uses #RECEIVEBYTES.
This client uses #RECEIVEALL with untillterm.
Client 2 with #RECEIVEALL is slightly faster.
However, it only works reliably using Network Events.
Greetings, Michael
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$
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
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$))
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
However, it only works reliably using Network Events.
Greetings, Michael
Last edited by msu on Tue Jun 04, 2019 2:31 pm, edited 1 time in total.
PostgreSQL-Library V1.0 Final: https://forum.amiga-resistance.info/vie ... =38&t=3591
Re: Problem with ReceiveData
Nice, that you sorted it out! Thanks for sharing your code.
But, what do you mean by "spreadsheet" and "table library"? Thanks!
But, what do you mean by "spreadsheet" and "table library"? Thanks!
Currently using: Hollywood 9 with Windows IDE and Hollywood 9 with Visual Studio Code and hw4vsc
Re: Problem with ReceiveData
Thank you, have corrected that.
PostgreSQL-Library V1.0 Final: https://forum.amiga-resistance.info/vie ... =38&t=3591
Re: Problem with ReceiveData
Thanks!
But I still don't know what "the table library" is!? Sorry, if I am too dumb to understand or unexperienced in Hollywood. I know the {} tables but I don't that there is a table library (built in to Hollywood?).
Thanks for your patience!
But I still don't know what "the table library" is!? Sorry, if I am too dumb to understand or unexperienced in Hollywood. I know the {} tables but I don't that there is a table library (built in to Hollywood?).
Thanks for your patience!
Currently using: Hollywood 9 with Windows IDE and Hollywood 9 with Visual Studio Code and hw4vsc
Re: Problem with ReceiveData
Alright, I see, thanks. I know these functions for manipulation a table (but wasn't aware of the term "library"). So you mean you should use a table as a data structure but don't use functions to manipulate the table in order to get the speed gain, right!?
Currently using: Hollywood 9 with Windows IDE and Hollywood 9 with Visual Studio Code and hw4vsc
Re: Problem with ReceiveData
Right, but only in terms of very large amounts of data.
PostgreSQL-Library V1.0 Final: https://forum.amiga-resistance.info/vie ... =38&t=3591