Search Issue Tracker

Not Reproducible

Votes

4

Found in

5.6.3p1

Issue ID

948886

Regression

No

Network Discovery always fails if Unity started with no Network Connection

Networking

-

To reproduce:

1. Download project "NetworkDiscoveryBug.zip", disable the Internet connection and open in Unity
2. Open "NetDiscoveryBug" scene
3. Enter Play mode
4. Press "Initialize Broadcast"
5. Press "Start Broadcasting"
Note: Observe that you should get an error that states "By some reason host doesn't have broadcast addreses" and "NetworkDiscovery StartBroadcast failed err: 8"
6. Right-Click on the "Network Manager and Discovery" MonoBehaviour to see the "Stop Broadcasting" context menu item and click it
Note: Observe that it won't work because NetworkDiscovery.running is false and yet its hostId != -1
7. Exit Play mode and close Unity Editor
8. Open this project again in Unity Editor
9. Open "NetDiscoveryBug" scene
10. Enter Play mode
11. Right-Click on the "Network Manager and Discovery" MonoBehaviour to see the "Start Broadcasting" context menu item and click it
Note: Observe that you will receive the error, but this time it recovers properly because the connection was closed manually. Even after plugging in a network cable and thus creating a network connection, choosing "Start Broadcasting" will fail. It will always fail from now on. The only solution is to restart Unity.

Reproduced on Unity 5.5.4p4, 5.6.3p3, 2017.1.1p1, 2017.2.0b11 and 2017.3.0a7

Comments (4)

  1. Jodon

    Oct 09, 2017 17:05

    Saying you're not sure this is a bug is bogus. People are going to read this and think "Not a bug? Good I don't have to fix it". You admit yourself "I still haven't solved the problem" is enough you need to know that even after finding this super obscure bug, it's nearly impossible to fix. Once initialized, you can't uninitialize it without tearing down the entire network system. There is no recovery, and no failure status. You can have virtual adapters that cause the call to succeed without error, and you're none the wiser. It takes hours of debugging to find a work-around.

    We have a much more complicated network setup than publicly addressable IP addresses. Our app works without internet, on a LAN-only and Network.TestConnection does not address it.

  2. DavidHidvegi

    Oct 09, 2017 10:23

    Found a solution!
    As I mentioned below, I'm not sure that it's a bug at all :P

    You must check wether you have connection to anything at all before initializing NetworkDiscovery :)

    The code I'm using for that is the following:

    public bool isConnectedToAnyNetwork()
    {
    if (Network.player.ipAddress == "0.0.0.0" || Network.player.ipAddress == "0.0.0.0.0.0")
    return false;
    return true;
    }

    Be sure to check it before initializing it on Client's side to!!!

    DevLove<3

  3. DavidHidvegi

    Oct 09, 2017 09:46

    Sry for the previous link, this is what we'll need I guess:

    https://docs.unity3d.com/ScriptReference/NetworkReachability.html

    DevLove<3

  4. DavidHidvegi

    Oct 09, 2017 09:35

    I have the same issue, but just some things to note:

    1.) You can start Listenning to broadcast as a Client even if you start with no network connection.
    2.) You can Initialize Broadcast if you start with no network connection (as a Client or Server)

    However, it also crashes if you Initialize the Broadcast (that you will want to have as server) without connection, and then the connection comes back and then you want to start it as a Server.

    So basically there is one thing you can't/must not do (which migth not even be a bug) which is the following:

    Do NOT Initialize or StartAsServer any Broadcast when you have no connection.

    It's kind of obvious, since I guess when you initialize it will search for an address/port that it will want to use to broadcast messages, but if you have no connection then you have no adresses/ports, I guess ?

    So... currently I'm trying to solve it with a workaround where I check if you have network connection, before Initialize and StartAsServer runs, and if you have no connection I tell that to the user. (I still haven't solved the problem)
    You can find more info on how to check Network Connection here:
    https://docs.unity3d.com/ScriptReference/Network.TestConnection.html

    DevLove<3

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.