simple network functions

BlitzMax Forums/BlitzMax Beginners Area/simple network functions

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I have spent some time looking at that GNet, and I have come up with the following, which works as far as sending information to the server. But what if there are more than one client contacting the server. How would I go about changing it so that it can know who is sending the data?

Server:
SuperStrict

Local host:TGNetHost = CreateGNetHost()
Local port:Int = 1234
Local address:String = "127.0.0.1"
Local timeout_ms:Int = 10000

Local listen:Int = GNetListen( host, port )
If Not listen Then RuntimeError "GNetListen failed"

Local remoteObj:TGNetObject
Local objList:TList = New TList

Local txt:String[32]
Local num:Int[32]

Graphics 320,240

While Not KeyHit(KEY_ESCAPE)

	Delay 10

	GNetSync host
	
	objList = GNetObjects( host, GNET_MODIFIED )
	For remoteObj = EachIn objList
		DrawText GetGNetString( remoteObj, 0 ), 10,10
		DrawText GetGNetString( remoteObj, 1 ), 10,20
		DrawText GetGNetString( remoteObj, 2 ), 10,30
		DrawText GetGNetInt( remoteObj, 3 ), 10,40
		DrawText GetGNetInt( remoteObj, 4 ), 10,50
		DrawText GetGNetInt( remoteObj, 5 ), 10,60
		DrawText GetGNetInt( remoteObj, 6 ), 10,70
	Next
	Flip
	
Wend
CloseGNetHost(host)
End


Client:
SuperStrict

Const GNETSLOT_NAME:Int = 0
Const GNETSLOT_STATS:Int = 1
Const GNETSLOT_VITALS:Int = 2
Const GNETSLOT_LOCALMAPX:Int = 3
Const GNETSLOT_LOCALMAPY:Int = 4
Const GNETSLOT_WORLDMAPX:Int = 5
Const GNETSLOT_WORLDMAPY:Int = 6

Local host:TGNetHost = CreateGNetHost()
Local port:Int = 1234
Local address:String = "127.0.0.1"
Local timeout_ms:Int = 10000

Local connect:Int = GNetConnect( host, address$, port, timeout_ms )
If Not connect Then RuntimeError "GNetConnect failed"

Local localObj:TGNetObject = CreateGNetObject:TGNetObject( host )

Graphics 480,360

While Not KeyHit(KEY_ESCAPE)

	Delay 10

	GNetSync host
	
	If KeyHit(KEY_SPACE) Then
		SetGNetString localObj,GNETSLOT_NAME,"Character Name"
		SetGNetString localObj,GNETSLOT_STATS,"18,9,16,11,13,10"
		SetGNetString localObj,GNETSLOT_VITALS,"108,32"
		SetGNetInt localObj,GNETSLOT_LOCALMAPX,100
		SetGNetInt localObj,GNETSLOT_LOCALMAPY,100
		SetGNetInt localObj,GNETSLOT_WORLDMAPX,0
		SetGNetInt localObj,GNETSLOT_WORLDMAPY,0
	End If
	
Wend
CloseGNetHost(host)
End


I was thinking that I could use the first slot of the object and use the player character name and then react to that. But I am not sure about what to do when having to send data back to the clients.

I am going to keep working on this and hopefully I will get some working code that will allow me to continue with the game idea. I just think that I need to have working network communication done before I move on.

Any input on effective ways of dealing with this is highly welcome.