Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;
- ; ------------------------------------------------------------
- ;
- ; PureBasic - ProjektX Server
- ;
- ; (c) 2011 - Christian Hofmann
- ;
- ; ------------------------------------------------------------
- ;
- Procedure CheckIncomingData(Daten.s)
- ; Daten zwischen <begin> und <end> heraussuchen
- PositionBegin.l
- PositionEnd.l
- String.s
- StringKomplett.s
- Anzahl.l
- laenge.l
- StringKomplett = Daten
- Repeat
- PositionBegin = FindString(StringKomplett, "<begin>", 1)
- PositionEnd = FindString(StringKomplett, "<end>", 1)
- laenge = Len(StringKomplett)
- If PositionBegin > 0
- String = Mid(StringKomplett, PositionBegin+7, PositionEnd-PositionBegin-7)
- StringKomplett = Right(StringKomplett,laenge-PositionEnd-4)
- PrintN(String)
- Else
- Quit = 1
- EndIf
- Until Quit = 1
- ProcedureReturn = 0
- EndProcedure
- OpenConsole()
- If InitNetwork() = 0
- PrintN("Can't initialize the network !")
- End
- EndIf
- Port = 6832
- *Buffer = AllocateMemory(1000)
- If CreateNetworkServer(0, Port)
- PrintN("Server created (Port "+Str(Port)+").")
- Repeat
- Delay(10)
- SEvent = NetworkServerEvent()
- If SEvent
- ClientID = EventClient()
- Select SEvent
- Case #PB_NetworkEvent_Connect
- PrintN("A new client has connected !")
- Case #PB_NetworkEvent_Data
- PrintN("Client "+Str(ClientID)+" has send a packet !")
- ReceiveNetworkData(ClientID, *Buffer, 1000)
- CheckIncomingData(PeekS(*Buffer))
- ;PrintN("String: "+PeekS(*Buffer))
- Case #PB_NetworkEvent_File
- ;PrintN("Client "+Str(ClientID)+" has send a file via the network !")
- ;ReceiveNetworkFile(ClientID, "C:\TEST_Network.ftp3")
- Case #PB_NetworkEvent_Disconnect
- PrintN("Client "+Str(ClientID)+" has closed the connection...")
- ;Quit = 1
- EndSelect
- EndIf
- Until Quit = 1
- PrintN("Click to quit the server.")
- CloseNetworkServer(0)
- Else
- PrintN("Can't create the server (port in use ?).")
- EndIf
- End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement