I havn't tested it, and it is only synchronisation and a little gameloop. For sending data, try something like integer 0, followed by integer frametime, followed by integer player id number (if you plan on having more than 2 players), followed by all data regarding this player, either terminate by integer 0, or write a new player number followed by the same kind of data etc. After terminating the player data section, go on with other stuff in the same manner (id, followed by set amount of data, terminate with 0).
I hope that I havn't confused more than I have helped.
I hope that I havn't confused more than I have helped.
Const host=0 Const client=1 Const logicrate=100 Global nulltime ip$="127.0.0.1" port=7777 localmachine=host ;or client If localmachine=host Then server=CreateTCPServer(port) Repeat stream=AcceptTCPStream(server) If stream<>0 Then Exit If KeyHit(1) Then RuntimeError "Waiting aborted" Forever Delay 1000 sendtime=MilliSecs() WriteInt stream,0 Repeat If ReadAvail(stream)>=4 Then nulltime=(MilliSecs()+sendtime)/2 ReadInt(stream) Exit End If Forever Else Repeat stream=OpenTCPStream(ip,port) If stream<>0 Then Exit If KeyHit(1) Then RuntimeError "Waiting aborted" Forever Repeat If ReadAvail(stream)>=4 Then nulltime=MilliSecs() WriteInt stream,0 ReadInt(stream) Exit End If Forever End If ;'the mark' ;load gfx etc if not already done If localmachine=host Then Repeat If ReadAvail(stream)>=4 Then ReadInt(stream) frametime=gametime()+1000 WriteInt stream,frametime Exit End If Forever Else WriteInt stream,0 Repeat If ReadAvail(stream)>=4 Then frametime=ReadInt(stream) Exit End If Forever End If frametime=frametime*logicrate Repeat While frametime>gametime*logicrate RenderWorld() ;all rendering stuff in here Flip Wend ;game logics, including updateworld go here frametime=frametime+1000 Forever Function gametime() Return MilliSecs()-nulltime End Function ;This should make a good setup for a 2 player realtime game, gametime() should return ;the same time on both computers. If you want multiple clients, you will need the code ;before 'the mark' to be run once for every client, afterwards the host must tell the ;clients how much they need to correct their nulltime. (Just use the difference in the ;nulltime's generated at the host end) ;You could eventually also set up a UDP stream for use during game.