GNet Connecting To Server
Blitz3D Forums/Blitz3D Programming/GNet Connecting To Server
| ||
I was wondering once I create a server on GNet how do I connect to it? Creating The Server Code: ;include all the functions Include "gnet_inc.bb" If HostNetGame("Server1") = 2 Then GNET_AddServer("Test","Server1") player = CreateNetPlayer("Server1") Print "Server Up" EndIf While Not KeyHit(1) Wend GNET_RemoveServer("Test") Trying To Reach It Code: ;include all the functions Include "gnet_inc.bb" GNET_ListServers() For gns.GNET_Server = Each GNET_Server Print gns\game$ + "," + gns\server$ + "," + gns\ip$ game$ = gns\game$ ip$ = gns\ip$ Next If JoinNetGame(game$,ip$) = 1 Then player = CreateNetPlayer("Player") Else RuntimeError "Failed To Join" EndIf While Not KeyHit(1) For gns.GNET_Server = Each GNET_Server Print gns\game$ + "," + gns\server$ + "," + gns\ip$ Next Print RecvNetMsg() Wend GNet Commands: 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 And yes I know that this will try to connect to the first server it finds but since mine was the only one up at the time I thought that would work. But no matter what I do I can't seem to connect to the server. |
| ||
Actually I have no idea what I'm doing. Can someone just explain how to make a host and a client connect using GNet? All the code out there seems to be either a 40KB wall of text or for BlitzMax. And a brief explanation of what GNet does wouldn't hurt. |
| ||
I can only offer minimal info on this. Gnet lists a "Host" game and lets you "try" to connect to it, but unless you port forward a series of port exceptions Gnet is not of much use unless your server is in a DMZ. Jeremy did a full FPS arena game in the code archs and I emailed him asking the same thing you are and how to make clients talk to the server and the port forward and dmz thing is what he said was needed. In other words, I would just find NET lib already tested and proven for B3D and go from there. Thats my 2 cents mate :) |