Advertisement
Guest User

Untitled

a guest
Sep 16th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;
  2. ; ------------------------------------------------------------
  3. ;
  4. ;   PureBasic - ProjektX Server
  5. ;
  6. ;    (c) 2011 - Christian Hofmann
  7. ;
  8. ; ------------------------------------------------------------
  9. ;
  10.  
  11. Procedure CheckIncomingData(Daten.s)
  12.   ; Daten zwischen <begin> und <end> heraussuchen
  13.   PositionBegin.l
  14.   PositionEnd.l
  15.   String.s
  16.   StringKomplett.s
  17.   Anzahl.l
  18.   laenge.l
  19.  
  20.   StringKomplett = Daten
  21.  
  22.   Repeat
  23.     PositionBegin = FindString(StringKomplett, "<begin>", 1)
  24.     PositionEnd = FindString(StringKomplett, "<end>", 1)
  25.     laenge = Len(StringKomplett)
  26.    
  27.     If PositionBegin > 0
  28.       String = Mid(StringKomplett, PositionBegin+7, PositionEnd-PositionBegin-7)
  29.    
  30.       StringKomplett = Right(StringKomplett,laenge-PositionEnd-4)
  31.    
  32.       PrintN(String)
  33.      
  34.     Else
  35.       Quit = 1
  36.     EndIf
  37.  
  38.   Until Quit = 1
  39.    
  40.   ProcedureReturn = 0
  41. EndProcedure
  42.  
  43. OpenConsole()
  44.  
  45. If InitNetwork() = 0
  46.   PrintN("Can't initialize the network !")
  47.   End
  48. EndIf
  49.  
  50. Port = 6832
  51. *Buffer = AllocateMemory(1000)
  52.  
  53. If CreateNetworkServer(0, Port)
  54.  
  55.  PrintN("Server created (Port "+Str(Port)+").")
  56.  
  57.  Repeat
  58.    Delay(10)
  59.      
  60.     SEvent = NetworkServerEvent()
  61.  
  62.     If SEvent
  63.    
  64.       ClientID = EventClient()
  65.  
  66.       Select SEvent
  67.      
  68.         Case #PB_NetworkEvent_Connect
  69.           PrintN("A new client has connected !")
  70.  
  71.         Case #PB_NetworkEvent_Data
  72.           PrintN("Client "+Str(ClientID)+" has send a packet !")
  73.           ReceiveNetworkData(ClientID, *Buffer, 1000)
  74.           CheckIncomingData(PeekS(*Buffer))
  75.           ;PrintN("String: "+PeekS(*Buffer))
  76.  
  77.         Case #PB_NetworkEvent_File
  78.           ;PrintN("Client "+Str(ClientID)+" has send a file via the network !")
  79.           ;ReceiveNetworkFile(ClientID, "C:\TEST_Network.ftp3")
  80.  
  81.         Case #PB_NetworkEvent_Disconnect
  82.           PrintN("Client "+Str(ClientID)+" has closed the connection...")
  83.           ;Quit = 1
  84.    
  85.       EndSelect
  86.     EndIf
  87.    
  88.   Until Quit = 1
  89.  
  90.   PrintN("Click to quit the server.")
  91.  
  92.   CloseNetworkServer(0)
  93. Else
  94.   PrintN("Can't create the server (port in use ?).")
  95. EndIf
  96.  
  97.  
  98. End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement