- Home /
Network.Connect returns NoError but no connection?
Hi, I'm developing an online game, I was testing it on my computer by building into an .exe, and run two different instances. Everything works fine, I can connect the other instance's room and such. I also tested with the other computer in our house (so still LAN)
Then I published the game online, and when tested with other users, nobody can enter nobody's game, but I can enter my own room from another browser tab.
Anyway, I'm trying to test and see what the error is. So I created a "console" script to write the error on screen.
Now I'm testing by trying to connect a closed room, naturally it does not connect, but still the NetworkConnectionError returns "NoError" , and the OnFailedToConnect() function is never called.
My code is this:
var error = Network.Connect(element);
printConsoleEntry("Connection attempt : " + error);
which prints "Connection attempt : NoError"
.
But at some point, I see in the "real console", in the unity editor window,
The connection request to 192.168.x.x:26500 failed. Are you sure the server can be connected to?
But it does not show immediately I press the "connect" button. It waits a little. And it only shows once, out of a 100 presses, So is there some kind of yielding?
I also tried to yield the error in a coroutine like :
var error = Network.Connect(element);
yield error;
printConsoleEntry("Connection attempt : "+error);
it always returns NoError.
so where is the error? How can I see it?
It's an asynchronous function. It can't return an error.
Ins$$anonymous$$d it has events, like "OnConnectedToServer"
Benproductions
Ok, but OnFailedToConnect() is not called neither. So how do I detect what the error is?
The it's either still trying to connect, or has connected.
either OnConnectedToServer
is called and the client connected, OnFailedToConnect
is called and the client failed to connect or the client is still connecting.
I know that it is not connected because I'm trying to connect to a closed room. And it should not take $$anonymous$$utes for it to know that a connection error is gonna happen right?
How is connecting to your game done? Do you use Unity's $$anonymous$$asterserver, does each client provide their address to everyone who wished to join or do you have a centralized server people try to connect to? I Ask because you are trying to connect to your LAN Address, which means you're using NAT... you should ins$$anonymous$$d be connecting to the public address which is given to the router, and set up port forwarding.