GNET "failed to add server" everytime

Blitz3D Forums/Blitz3D Programming/GNET "failed to add server" everytime

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.

This code is working perfectly for me,

try to see if there's any difference with yours:

this is the "gnet_inc.bb":

Const GNET_HOST$="www.blitzbasic.com"
Const GNET_PORT=80
Const GNET_GET$="/gnet/gnet.php"

Type GNET_Server
	Field game$,server$,ip$
End Type

Function GNET_Esc$( t$ )
	t$=Replace$( t$,"&","" )
	t$=Replace$( t$,"%","" )
	t$=Replace$( t$,"'","" )
	t$=Replace$( t$,Chr$(34),"" )
	t$=Replace$( t$," ","_" )
	Return t$
End Function

Function GNET_Open( opt$ )
	t=OpenTCPStream( GNET_HOST$,GNET_PORT )
	If Not t Return 0
	
	WriteLine t,"GET "+GNET_GET$+"?opt="+opt$+" HTTP/1.0"
	WriteLine t,"HOST: "+GNET_HOST$
	WriteLine t,""
	
	While ReadLine$(t)<>""
	Wend
	
	Return t
End Function

Function GNET_Exec( opt$,game$,server$ )
	opt$=opt$+"&game="+GNET_Esc$(game$)
	If server$<>"" opt$=opt$+"&server="+GNET_Esc$(server$)
	t=GNET_Open( opt$ )
	If Not t Return 0
	
	ok=False
	If( ReadLine$(t)="OK" ) ok=True
	
	CloseTCPStream t
	Return ok
End Function

Function GNET_Ping$()
	t=GNET_Open( "ping" )
	If Not t Return 0
	
	ip$=ReadLine$(t)
	
	CloseTCPStream t
	Return ip$
End Function

Function GNET_AddServer( game$,server$="" )
	Return GNET_Exec( "add",game$,server$ )
End Function

Function GNET_RefreshServer( game$,server$="" )
	Return GNET_Exec( "ref",game$,server$ )
End Function

Function GNET_RemoveServer( game$ )
	Return GNET_Exec( "rem",game$,"" )
End Function

Function GNET_ListServers( game$="" )
	Delete Each GNET_Server
	t=GNET_Open( "list" )
	If Not t Return 0
	
	Repeat
		t_game$=ReadLine$(t)
		If t_game$="" Exit
		t_server$=ReadLine$(t)
		t_ip$=ReadLine(t)
		If game$="" Or game$=t_game$
			p.GNET_Server=New GNET_Server
			p\game$=t_game$
			p\server$=t_server$
			p\ip$=t_ip$
		EndIf
	Forever
	
	CloseTCPStream t
	Return 1
	
End Function



this is the testing code:
;Simple gnet demo
;
;Check out www.blitzbasic.com/gnet/gnet_servers.php while running!
;

Include "gnet_inc.bb"

my_game$="My_Game_TestingGNet"

;ping!
Print "Ping:"+GNET_Ping()
Print ""

;list active servers
;
ListServers()

;add a server!
;
Print "Adding server..."
Print ""

If Not GNET_AddServer( my_game$ )
	RuntimeError "Failed to add server"
EndIf

;list active servers
;
ListServers()

;refresh server!
;
Input "Hit return to refresh server..."
Print ""

If Not GNET_RefreshServer( my_game$,"New Server Name!" )
	RuntimeError "Failed to refresh server"
EndIf

;list active servers
;
ListServers()

;remove ourselves!
;
Input "Hit return to remove server and exit..."
Print ""

If Not GNET_RemoveServer( my_game$ )
	RuntimeError "Failed to remove server"
EndIf

End

Function ListServers()
	If Not GNET_ListServers()
		RuntimeError "Failed to list servers"
	EndIf
	
	Print LSet$("Game",16)+LSet$("Server",32)+LSet$("IP",16)
	Print String$("-",64)
	For t.GNET_Server=Each GNET_Server
		Print LSet$(t\game$,16)+LSet$(t\server$,32)+LSet$(t\ip$,16)
	Next
	Print ""
End Function



Paolo.

[EDIT] Anyway, for GNet I suggest using ETNA
http://repeatuntil.online.fr/Etna/