anyway it made me wonder - and i dont know how easy or practical it is, but it might be good to have a WaitNetworkEvent, similar to how WaitWindowEvent behaves but for NetworkServerEvent/NetworkClientEvent? to complement the current polling loop option
WaitNetworkEvent (the PB Server example uses 100% CPU)
WaitNetworkEvent (the PB Server example uses 100% CPU)
the Network Server example in the PB helpfile uses 100% CPU because it polls NetworkServerEvent(). When I add a Delay(1) to the end of the polling loop that brings CPU back down to 0%, so maybe the documentation should mention something about that?
anyway it made me wonder - and i dont know how easy or practical it is, but it might be good to have a WaitNetworkEvent, similar to how WaitWindowEvent behaves but for NetworkServerEvent/NetworkClientEvent? to complement the current polling loop option
anyway it made me wonder - and i dont know how easy or practical it is, but it might be good to have a WaitNetworkEvent, similar to how WaitWindowEvent behaves but for NetworkServerEvent/NetworkClientEvent? to complement the current polling loop option
Re: WaitNetworkEvent (the PB Server example uses 100% CPU)
The problem is that even if you add Delay() with only 1ms, it will make your network server very slow ^^
So better should be dynamically adjusting delay, depending of is network idle (can use delay to decrease CPU usage) or there is any data sending/receiving (delay removed)
Something WaitNetworkEvent() would be nice of course
So better should be dynamically adjusting delay, depending of is network idle (can use delay to decrease CPU usage) or there is any data sending/receiving (delay removed)
Something WaitNetworkEvent() would be nice of course
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
Re: WaitNetworkEvent (the PB Server example uses 100% CPU)
but if I Delay(more than 1) - assuming thats what you meant by dynamic - it'll just makes my app slower to respond? might even cause a bottleneck with several connections at the same time?The problem is that even if you add Delay() with only 1ms, it will make your network server very slow ^^
So better should be dynamically adjusting delay
Re: WaitNetworkEvent (the PB Server example uses 100% CPU)
use a delay only when there is no event (#PB_NetworkEvent_None).
c ya,
nco2k
c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Re: WaitNetworkEvent (the PB Server example uses 100% CPU)
This also slows down the application:nco2k wrote: Sat Jun 11, 2016 4:41 am use a delay only when there is no event (#PB_NetworkEvent_None).
Code: Select all
Event = NetworkServerEvent()
If Event
...
Else
Delay(1)
EndIfRe: WaitNetworkEvent (the PB Server example uses 100% CPU)
How are you noticing the delay? I'm spamming my server with data (even splitting it using StringField for packet buffering) and not noticing. Perhaps i'm testing wrong, though.
All that said though I agree, a WaitNetworkEvent() function would be extremely handy.
All that said though I agree, a WaitNetworkEvent() function would be extremely handy.
Re: WaitNetworkEvent (the PB Server example uses 100% CPU)
WaitNetworkEvent() only optional.
Because how you will terminate such a process?
Normally I do the network stuff in a thread.
With WaitNetworkEvent() I have to kill the thread. Very ugly.
Because how you will terminate such a process?
Normally I do the network stuff in a thread.
With WaitNetworkEvent() I have to kill the thread. Very ugly.
Re: WaitNetworkEvent (the PB Server example uses 100% CPU)
Yeah, I'd want it to work like (Wait)WindowEvent(), so we have both a wait and non-wait version.
Re: WaitNetworkEvent (the PB Server example uses 100% CPU)
Couldn't you just code this? You really only want to delay when there is no event, otherwise, you want it to be as fast as possible, so I wouldn't.. I do the 2nd example.Quin wrote: Thu Apr 27, 2023 9:36 pm Yeah, I'd want it to work like (Wait)WindowEvent(), so we have both a wait and non-wait version.
Something like:
Code: Select all
Procedure WaitNetworkServerEvent(nTimeout, ServerID)
Protected nEvent, now=ElapsedMilliseconds()
Repeat
nEvent = NetworkServerEvent(ServerID)
If nEvent<>#PB_NetworkEvent_None
break
EndIf
delay(1)
Until ElapsedMilliseconds()-now >= nTimeout
ProcedureReturn nEvent
EndProcedure
Code: Select all
Repeat
nEvent = NetworkServerEvent()
Select nEvent
Case #PB_NetworkEvent_Data
Case #PB_NetworkEvent_Connect
Case #PB_NetworkEvent_Disconnect
Case #PB_NetworkEvent_None
Delay(1)
EndSelect
Until ExitSignal
Just my $.02
Re: WaitNetworkEvent (the PB Server example uses 100% CPU)
Sorry, I think my statement was wrong. The error is in my program, I will investigate it.


