TCP Networking Help

Blitz3D Forums/Blitz3D Beginners Area/TCP Networking Help

ok, i kinda got it woking, but now the client and server are writing independently from each other, reading their own coordinates. How do I prevent this?
code:
Function GUI()

host=Input ("1-Host,2-join")

If host=1

Print "Creating Server on port 8080"

svrgame=CreateTCPServer(8080)
Print "Server Started Succesfully"

Delay 500

Else

Print "Joining..."

svrclnt=CreateTCPServer(8000)

Print svrclnt

Print "Stream Connected"

Delay 100

EndIf 

End Function 


Function UpdateNetWork()

If host=2 ;CLIENT


Text 0,200,svrclnt

;Read Streams
strm=AcceptTCPStream(svrclnt)

If strm Then 
plx#=ReadFloat#(strm)
ply#=ReadFloat#(strm)
plz#=ReadFloat#(strm)
plyaw=ReadLine(strm)
plpitch=ReadLine(strm)
plroll=ReadLine(strm)
CloseTCPStream strm
EndIf 

Cls 
Text 300,100,plx#
Text 300,150,ply#
Text 300,200,plz#
Flip 

wrtstrm=OpenTCPStream("127.0.0.1",8000)

;Write Stream
For p.pl=Each pl 
WriteFloat(wrtstrm,EntityX(p\cam))
WriteFloat(wrtstrm,EntityY(p\cam))
WriteFloat(wrtstrm,EntityZ(p\cam))
WriteInt(wrtstrm,EntityYaw(p\cam))
WriteInt(wrtstrm,EntityPitch(p\cam))
WriteInt(wrtstrm,EntityRoll(p\cam))
DebugLog "Sent"+wrtstrm
Next 

CloseTCPStream(wrtstrm)

Else ;if HOSTING

;Read Streams
strm=AcceptTCPStream(svrgame)

If strm Then 
plx#=ReadFloat#(strm)
ply#=ReadFloat#(strm)
plz#=ReadFloat#(strm)
plyaw=ReadLine(strm)
plpitch=ReadLine(strm)
plroll=ReadLine(strm)
CloseTCPStream strm
EndIf 


wrtstrm=OpenTCPStream("127.0.0.1",8080)

;Write Stream
For p.pl=Each pl 
WriteFloat(wrtstrm,EntityX(p\cam))
WriteFloat(wrtstrm,EntityY(p\cam))
WriteFloat(wrtstrm,EntityZ(p\cam))
WriteInt(wrtstrm,EntityYaw(p\cam))
WriteInt(wrtstrm,EntityPitch(p\cam))
WriteInt(wrtstrm,EntityRoll(p\cam))
DebugLog "Sent"+wrtstrm
Next 

CloseTCPStream(wrtstrm)

EndIf 

End Function