DirectPlay example

Blitz3D Forums/Blitz3D Programming/DirectPlay example

mhorvatic(Posted 2005) [#1]
Hello,

Could someone post a directplay example of a client server communication?

Thanks,
Marko


jfk EO-11110(Posted 2005) [#2]
Isn't there an example in the documentation?


mhorvatic(Posted 2005) [#3]
i couldn't find one that simulates both server and client


_PJ_(Posted 2005) [#4]
Copied from Docs:

----------Note the line:

run the example for RecvNetMsg() on a remote computer




; SendNetMsg example 
; ------------------ 
; Run this example on the local computer 
; run the example for RecvNetMsg() on a remote computer 

; Graphics mode with double buffering 
Graphics 640,480,16,3 
SetBuffer BackBuffer() 

; Create a network game with NO requester 
joinStatus=HostNetGame("ShaneGame") 

; A type to hold all the player's information 
Type multi 
Field x 
Field y 
Field id 
Field name$ 
Field xspeed 
Field boxColor 
End Type 

; make sure the game started ok... 
If joinStatus=2 Then 
Print "Hosted game started... " 
Else 
Print "Hosted game could not be started!" 
End 
End If 

; Create 5 local players using TYPEs 
For t = 1 To 5 
; New type instance 
player.multi = New Multi 
; Assign the ID field with the created player ID and name him 
playerID=CreateNetPlayer("Player" + t) 

; if the player was created ok ... assign some random parameters 
If playerID <> 0 Then 
player\name$="Player" + t 
player\x = Rand(640) 
player\y = Rand(480) 
player\boxColor = Rand(255) 
player\xspeed = Rand(1,5) 
; Print some text results 
Print "Player " + t + " has joined the game with ID=" + playerID 
Else 
Print "The player couldn't join! Aborting!" 
End If 
Next 

; We've got them all! Wait for a key 
Print "All local players are joined! Press a key ..." 
WaitKey() 

; Loop this routine 
While Not KeyHit(1) 
Cls 
; for each of the players, update their locations on the screen 
For player = Each multi 
Color player\boxColor,player\boxColor,player\boxColor 
Rect player\x,player\y,10,10,1 
Text player\x-10,player\y-15,player\name$ 
player\x = player\x + player\xspeed 
If player\x > 640 Or player\x < 0 Then 
player\xspeed=-player\xspeed 
message$="Player ID #" + playerID + " hit a wall!" 
; Send a broadcast message if a player rebounds off the wall 
; this message will show up on the remote machine 
SendNetMsg Rand(1,99),message$,playerid,0 
End If 
Next 
Flip 
Wend 
End