LAN Play

Blitz3D Forums/Blitz3D Programming/LAN Play

Hey Guys,

Does anybody know how you would setup a multiplayer game ONLY on your local network??

It's the same as if it's on mutiple networks. Use UDP. Directplay is too slow.

Can you give me an example of how to setup a LAN multiplayer game??

p.s Thanks for responding KillerX :) Oh, and the pulse rifle's bullets are comming along GREAT :D

AppTitle "Fastalker"
Graphics 800,600,0,2
FileOut = ReadFile("IP.txt")
Global Name$ = ReadLine(FileOut)
Global NumberOfPlayers = ReadLine(FileOut)
Global Signin$ = ReadLine(FileOut)
Global Signout$ = ReadLine(FileOut)
;Global Signature$ = ReadLine(FileOut)
Global MessageSound% = ReadLine(FileOut)
Dim IPAdress%(NumberofPlayers)
For Loop = 1 To NumberofPlayers
IPAdress(Loop) = ReadLine(FileOut)
Next
Global Sound = LoadSound("ReceivedMessage.wav")
Global Stream% = CreateUDPStream(828)
Global NewStream% = CreateUDPStream(79)


Repeat
IP = RecvUDPMsg(NewStream)


For Loop = 1 To NumberofPlayers
If IP = IPAdress(Loop) Message = 1
Next
If Message = 1
Message = 0
If MessageSound = 1 PlaySound Sound
String1$ = ReadString$(NewStream)
Print String1
EndIf

If KeyHit(28)
FlushKeys
Variable$ = Name + ": " + Input(Name + ": ")
Broadcast(Variable,79,0)
FlushKeys
EndIf


If KeyHit(2) And NumberOfPlayers >=1
FlushKeys
Variable$ = Name + ": " + Input(Name + ": ")
Broadcast(Variable,79,1)
FlushKeys
EndIf


If KeyHit(3) And NumberOfPlayers >=2
FlushKeys
Variable$ = Name + ": " + Input(Name + ": ")
Broadcast(Variable,79,2)
FlushKeys
EndIf


If KeyHit(4) And NumberOfPlayers >=3
FlushKeys
Variable$ = Name + ": " + Input(Name + ": ")
Broadcast(Variable,79,3)
FlushKeys
EndIf


If KeyHit(5) And NumberOfPlayers >=4
FlushKeys
Variable$ = Name + ": " + Input(Name + ": ")
Broadcast(Variable,79,4)
FlushKeys
EndIf


If KeyHit(6) And NumberOfPlayers >=5
FlushKeys
Variable$ = Name + ": " + Input(Name + ": "); + Signature
Broadcast(Variable,79,5)
FlushKeys
EndIf


If KeyHit(7) And NumberOfPlayers >=6
FlushKeys
Variable$ = Name + ": " + Input(Name + ": ")
Broadcast(Variable,79,6)
FlushKeys
EndIf


If KeyHit(8) And NumberOfPlayers >=7
FlushKeys
Variable$ = Name + ": " + Input(Name + ": ")
Broadcast(Variable,79,7)
FlushKeys
EndIf


If KeyHit(9) And NumberOfPlayers >=8
FlushKeys
Variable$ = Name + ": " + Input(Name + ": ")
Broadcast(Variable,79,8)
FlushKeys
EndIf


If KeyHit(10) And NumberOfPlayers >=9
FlushKeys
Variable$ = Name + ": " + Input(Name + ": ")
Broadcast(Variable,79,9)
FlushKeys
EndIf


If KeyHit(11) And NumberOfPlayers >=10
FlushKeys
Variable$ = Name + ": " + Input(Name + ": ")
Broadcast(Variable,79,10)
FlushKeys
EndIf

;sign in and out
If KeyHit(199)
FlushKeys
Variable$ = Name + ": " + Signin
Print Name + ": " + Signin
Broadcast(Variable,79,10)
FlushKeys
EndIf



If KeyHit(207)
FlushKeys
Variable$ = Name + ": " + Signout
Print Name + ": " + Signout
Broadcast(Variable,79,10)
FlushKeys
EndIf




Until KeyHit(1)
WaitKey
End


Function Broadcast(Message$,Port,Recipient);Message is the stream that is being broadcasted.  Port is the Destination Port.
If Recipient = 0
For Loop = 1 To NumberofPlayers
WriteString(Stream,Message)
SendUDPMsg Stream,IPAdress(Loop),Port
Next
Else
WriteString(Stream,Message)
SendUDPMsg Stream,IPAdress(Recipient),Port
EndIf
End Function

This is for a UDP Chat program that I wrote.

Thanks KillerX :)

But is it possible to use DirectPlay and ONLY connect for a LAN game?

No. It's far too slow to use in realtime. You could possibly use it for a turn based game though.

Could anybody show me a small example of just how to connect to the computers on a local network. For example: I have three computers and I want to setup sort of like a Chinees Checkers game. How would you connect them through Blitz3D. They are all connected on my local network though.

[edit]

Here is what I have so far:

Global connect = OpenTCPStream("My IP",1)

game = StartNetGame()

If game = 0

	Print "Failed."
	
ElseIf game = 1

	Print "Joined."
	
ElseIf game = 2

	Print "Started."
	
EndIf

WaitKey

CloseTCPStream connect


I run that when I'm hosting a game on my machine and when I fill everything out with the DirectPlay box, it works fine. But when I try to do that on another machine that is on my local network, it doesn't work.

What port number does it have to be??

[/edit]

Well, what I would do is set up a sort of server-client thing. Have one of the computers on your network work as a server:


port=input("What port: ")
tcp=CreateTCPServer(port)



Then, I'm pretty sure that you can just do this for the clients:


serverip$="192.168.1.1"
port=8080
tcp=OpenTCPStream(serverip$,port)



Just set port to whatever you set the server at, then change serverip$ to the local IP of the server comp.

Thnx xtremegamr :)