Page 1 of 1

#PB_Event_Network

Posted: Thu Oct 13, 2005 9:54 pm
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

Posted: Thu Oct 13, 2005 10:05 pm
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.

Posted: Thu Oct 13, 2005 10:08 pm
by Flype
yes but with an optional NetworkAttachWindow(WindowID()) like in my example it should be possible, no ?

Posted: Thu Oct 13, 2005 11:04 pm
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

Posted: Thu Oct 13, 2005 11:34 pm
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).

Posted: Thu Oct 13, 2005 11:36 pm
by blueznl
winsock will allow messages to be sent to a window upon events, so a normal windowevent() or waitwindowevent() may be possible

Posted: Fri Oct 14, 2005 1:26 am
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