Search Unity

BroadcastDiscovery multiple clients on the same machine

Discussion in 'Multiplayer' started by Jacktang, Aug 13, 2015.

  1. Jacktang

    Jacktang

    Joined:
    Jul 6, 2012
    Posts:
    15
    Hello, I'm trying to get broadcast discovery working in my game using the LLAPI and have run into a bit of a snag which I think only really impacts testing as far as I can tell.

    As soon as the player launches my game, I want broadcast discovery to start so that I can show them a little icon on the homepage if there's a game in progress on their local network. So in order to do that, as soon as the player launches my game I need to enable broadcast discovery.

    The issue I'm running into is that I need to open a socket to the broadcast port, but when testing locally I have multiple instances of the app open on the same computer so the first one to connect gets the socket on my broadcast port, and any subsequent clients I launch all fail to initialize their sockets as it's already in use.

    The next thing I tried was to attempt to broadcast to a range of ports (there's only a max of 4 players) so I put NetworkTransport.StartBroadcastDiscovery into a loop on my server, but it would seem that broadcastDiscovery can only be enabled for a single port at a time.

    I do not have another computer that I can test this with currently, but I imagine that the issue would go away when running clients on different devices. My question is, is there a way around this little issue, or am I going to have to ensure I'm always testing on different devices?
     
  2. Jacktang

    Jacktang

    Joined:
    Jul 6, 2012
    Posts:
    15
    I found out that this should be possible by simply setting the
    SO_REUSEADDR option when binding the socket to the application. It doesn't look like this is exposed by unity though. Is it possible to open my own socket using the system.net.sockets apis and bind it to the application while still utilizing the rest of the Unity networking APIs?
     
  3. rasputingoldfish

    rasputingoldfish

    Joined:
    Aug 23, 2015
    Posts:
    2
    I am having the same problem. Did you figure out how to do this?