#PB_Event_Network

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

#PB_Event_Network

Post by Flype »

in many situations, it might be easier to catch Network events in the classic event window loop.
so what about something like this ?

Code: Select all

If InitNetwork()
  
  If CreateNetworkServer(6832)
    
    OpenWindow(0,50,50,640,480,#PB_Window_SystemMenu,"Test")
    
    NetworkAttachWindow(WindowID())
    
    Repeat
      
      Select WaitWindowEvent()
        
        Case #PB_Event_CloseWindow
          Break
          
        Case #PB_Event_Network_Connect
          Debug NetworkClientID()
          
        Case #PB_Event_Network_Disconnect
          Debug NetworkClientID()
          
        Case #PB_Event_Network_Raw
          Debug NetworkClientID()
          
        Case #PB_Event_Network_File
          Debug NetworkClientID()
          
      EndSelect
      
    ForEver
    
  EndIf
  
EndIf
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Killswitch
Enthusiast
Enthusiast
Posts: 731
Joined: Wed Apr 21, 2004 7:12 pm

Post by Killswitch »

That would be cool, but network events aren't directly tied to a window. Perhaps WindowEvent() and the NetworkServer/ClientEvents() should be ditched for one Event() command.
~I see one problem with your reasoning: the fact is thats not a chicken~
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

yes but with an optional NetworkAttachWindow(WindowID()) like in my example it should be possible, no ?
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

I actually want a WaitNetworkEvent

Code: Select all

If WaitWindowEvent() or WaitNetworkEvent()
  Select WindowEvent()
    ;window events
  EndSelect

  Select NetworkEvent()
    ;network events
  EndSelect
endif
I like logic, hence I dislike humans but love computers.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

This code won't work as the program will hold on WaitWindowEvent() and you will have no chance to unlock WaitNetworkEvent(). We could may be implement a WaitEvent() function which would lock and returns if an event occurs (dunno if it's really possible).
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

winsock will allow messages to be sent to a window upon events, so a normal windowevent() or waitwindowevent() may be possible
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Fred wrote:We could may be implement a WaitEvent() function which would lock and returns if an event occurs (dunno if it's really possible).
That would be cool, there must be a way, hehe.
Edit:
I just found the solutuion for my problem:

Code: Select all

Repeat
  WindowEvent = WindowEvent()
  Select Status
    Case #Server
      NetworkEvent = NetworkServerEvent()
    Case #Client
      NetworkEvent = NetworkClientEvent(ServerID)
  EndSelect
  
  If WindowEvent=#False And NetworkEvent=#False
    Delay(4)
    Continue
  EndIf
  
  Select WindowEvent
    ;window events 
  EndSelect 

  Select NetworkEvent
    ;network events 
  EndSelect 
Until WindowEvent = #PB_Event_CloseWindow
I like logic, hence I dislike humans but love computers.
Post Reply