GNet issue with local network

BlitzMax Forums/BlitzMax Programming/GNet issue with local network

Vignoli(Posted 2015) [#1]
Hi,

I'm making a program using GNet.

When i run it a first time as host and a second time as client in the same computer with IP 127.0.0.1, no problem, the connexion is ok.

But if i run as host my PC and as client my Mac using my local fixed IP (192.168.1.X), i can't get any connexion.

An idea ?

EDIT: If i use local fixed IP (192.168.1.X) with two instances of the program in the same computer, all works too.


Scaremonger(Posted 2015) [#2]
Check your local firewall, but if not; please post some example code.


Vignoli(Posted 2015) [#3]
This is only the GNet part, my source is long.
...

				Case Bouton1
					Joueur[0] = GadgetText(TextField1)
					If Len(Joueur[0]) > 0
						' Tenter la connexion
						Host = CreateGNetHost()
						If ButtonState( Checkbox2 ) > 0
							' Connexion host
							numeroJoueur = 0
							JoueurCount = 1
							If Not GNetListen( Host, Port ) Then
								RuntimeError "Impossible d'écouter le port "+String( Port )+" !"
							EndIf
							localObj = CreateGNetObject:TGNetObject( Host )
							Exit
						Else
							' Connexion client
							numeroJoueur = 0
							Adresse = GadgetText( TextField2 )
							If Not GNetConnect( Host, Adresse , Port, 10000 )
								Notify "Impossible de se connecter !"
								End
							EndIf
							localObj = CreateGNetObject:TGNetObject( Host )
							Local done:Int = False
							SetGNetString localObj, 0, "<REQUEST_PLAYER_NUMBER>" + GadgetText( TextField1 )
							SetGNetInt localObj, 1, 0
							While done = False
								Delay 10
								PollEvent
								GNetSync Host
								objList = GNetObjects( Host, GNET_MODIFIED )
								For remoteObj = EachIn objList
									Local msg:String = GetGNetString( remoteObj, 0 )
									Local value:Int = GetGNetInt( remoteObj, 1 )
									If msg = "<PLAYER_ALLOWED>" + GadgetText( TextField1 )
										numeroJoueur = value
										done = True
										Exit
									ElseIf msg = "<PLAYER_NOT_ALLOWED>" + GadgetText( TextField1 )
										numeroJoueur = 0
										done = True
										Exit
									EndIf
								Next
								If done = True
									SetGNetString localObj, 0, ""
									SetGNetInt localObj, 1, 0
									GNetSync Host
									Exit
								EndIf
							Wend
							If numeroJoueur = 0
								CloseGNetHost( Host )
								Notify "Maximum des joueurs atteint : 15 PJ + 1 MJ."
								End
							EndIf
							JoueurCount = 2
							Exit
						EndIf
					EndIf


...

Repeat

	Delay 10

	If numeroJoueur = 0
		GNetSync Host
		objList = GNetObjects( Host, GNET_CREATED )
		For remoteObj = EachIn objList
			Local msg:String = GetGNetString( remoteObj, 0 )
			Local value:Int = GetGNetInt( remoteObj, 1 )
			If Left(msg,23) = "<REQUEST_PLAYER_NUMBER>" And JoueurCount < MaxJoueur
				SetGNetString localObj, 0, "<PLAYER_ALLOWED>" + Mid(msg, 24)
				SetGNetInt localObj, 1, JoueurCount
				Notify Mid(msg, 24) +" vient de rejoindre la partie !"
				JoueurCount = JoueurCount + 1
			ElseIf Left(msg,23) = "<REQUEST_PLAYER_NUMBER>"
				SetGNetString localObj, 0, "<PLAYER_NOT_ALLOWED>" + Mid(msg, 24)
				SetGNetInt localObj, 1, 0
			ElseIf msg = ""
				SetGNetString localObj, 0, ""
				SetGNetInt localObj, 1, 0			
			EndIf
		Next
	EndIf
	
	WaitEvent()


...


Vignoli(Posted 2015) [#4]
Do i have to choose a special port for GNet ?
I've seen that a TCP connexion needs port 6660.
And i've set the port 8086 for my GNet connexion because i've seen it in a example... that is not working.

(I'm a perfect noob about that)


Scaremonger(Posted 2015) [#5]
Hi,

The TCP Port you use must be the same on both Server and Client and needs to be between 1024 and 65535. 8086 should be fine. Because this works when both are on the same PC I expect the Port you are using is correct.

I would suggest checking that GNetListen() is successful on your host (PC) and confirm it's IP address before investigating the client.

A common error is starting the Client before the Host is running. Does your application fail during GNetConnect() or GNetListen() ?


Vignoli(Posted 2015) [#6]
GNetConnect fails when my client try to join the host, but only if i use 2 different computers.
On a same computer, i can run the first instance of the program as host, and join it with multiples other instances.
I've tried to set a NAT/PAT exception for to test an external network too, but without success.


Vignoli(Posted 2015) [#7]
Yeah, i've found the bug : it was the "WaitEvent()" command who prohibit any connexion.

Thanks for your help.