Blitz3D+ Command Reference

JoinNetGame ( game_name$,ip_address$ )

Parameters

game_name$ - name of the game to join (must match the name it was hosted with)

ip_address$ - IP address of the machine hosting the game, e.g. "192.168.1.10"

Description

Joins a network game hosted on another machine, without showing the StartNetGame dialog.

The host's address and the exact game name identify the session. Returns 1 if the game was joined, 0 if not - wrong name, wrong address, or no host listening.

After joining, create a player with CreateNetPlayer (everyone in the session gets a join message, type 100), then send and receive with SendNetMsg and RecvNetMsg. Leave with StopNetGame. Only one session can be active at a time - joining while another is running raises a runtime error.

To test on a single PC, host in one copy of your program and join from a second copy with the loopback address "127.0.0.1".

See also: HostNetGame, StartNetGame, StopNetGame, CreateNetPlayer.

Example

; JoinNetGame Example
; -------------------

; JoinNetGame joins a named game on a known IP address directly,
; skipping the StartNetGame dialog. It returns 1 on success.
;
; Run the HostNetGame example in another copy of Blitz3D+ FIRST,
; then run this program - it joins the host over loopback.

Print "Looking for 'demo game' on 127.0.0.1 ..."
status=JoinNetGame("demo game","127.0.0.1")

If status=1 Then
    Print "JoinNetGame returned 1 - joined the game!"

    ; Create our player; the host is notified that we joined
    guest=CreateNetPlayer("Guest")
    Print "Playing as '"+NetPlayerName$(guest)+"'"

    ; Message type 100 tells us about players already in the game
    start=MilliSecs()
    While MilliSecs()-start<3000
        If RecvNetMsg() Then
            If NetMsgType()=100 Then Print "Found player '"+NetPlayerName$(NetMsgFrom())+"' in the game"
        EndIf
        Delay 10
    Wend

    StopNetGame
    Print "Left the game"
Else
    Print "JoinNetGame returned "+status+" - no 'demo game' found."
    Print "Start the HostNetGame example in another copy first,"
    Print "then run this example again while it is listening."
EndIf

Print ""
Print "Press any key to close the example"
WaitKey

End

Index