Code: Select all
Repeat
Protected Event.w = NetworkServerEvent()
If Event
ClientID.q = EventClient()
Select Event
;Someone new has connected to us
Case #PB_NetworkEvent_Connect
SendNetworkMessage( "Client " + IPString(GetClientIP(ClientID)) + " is trying to connect..." )
;Ask for connection data
PokeB(*NetworkBuffer, #Network_EstablishConnection)
SendNetworkData(ClientID, *NetworkBuffer, 1)
;Someone is trying to send us some network data
Case #PB_NetworkEvent_Data
ReadNetworkData( ClientID )
;Someone is sending us a file!? We dont want that!
Case #PB_NetworkEvent_File
;Ignore file sending! Simply drop the packet
;Someone has disconnected from us
Case #PB_NetworkEvent_Disconnect
PrintN("Client " + Str(ClientID) +" has closed the connection...")
DisconnectClient(ClientID, "Client has disconnected.", #True)
EndSelect
EndIf
Until Not Event
Code: Select all
Procedure ReadNetworkData(ConnectionID)
RecieveNetworkData( ConnectionID, *NetworkBuffer, 2048 )
Header = PeekB(*NetworkBuffer)
Select Header
Case #Network_MessagePacket
;code for handling packets of "message" type here
Case #Network_PingPacket
;code for handling packets of "ping" type here
Case #Network_HelloPacket
;code for handling packets of "hello" type here
EndSelect
EndProcedure


