Search Unity

UDP Broadcast

Discussion in 'Multiplayer' started by demonpants, Dec 1, 2008.

  1. demonpants

    demonpants

    Joined:
    Oct 3, 2008
    Posts:
    82
    Does Unity support doing a UDP broadcast for discovering other players on a LAN? If that's not clear enough, basically right now we've got people typing in the IP address of the other player, and I want to have the host broadcasting their IP address so that the clients can automatically discover it and display the results in a list.

    I know I could use the Unity MasterServer for this, but that's not the best option for LAN games because then I'm requiring people to have the ports open to connect to the master server, as well as an internet connection. This defeats the purpose of a LAN game in many ways.
     
  2. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
  3. demonpants

    demonpants

    Joined:
    Oct 3, 2008
    Posts:
    82
    Great, thanks, I'll try that out. Can I use that from inside a MonoBehaviour or do I need an external library/plugin?
     
  4. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    You'll need an import of the namespace (in C# that's "import namespaceName;", there's something similar in JS but I don't know that syntax) to use those classes in your MonoBehaviour, or you could use "fully qualified classnames" (prefix the classname with the namespace).

    Unity *should* automatically include the necessary assembly DLLs.

    I'm assuming that you're not doing Web players. If you do, you need to be aware that using anything from the .NET libraries that's not in mscorlib.dll will increase the Web player download size, so one needs to be a little careful with that.
     
  5. demonpants

    demonpants

    Joined:
    Oct 3, 2008
    Posts:
    82
    Our project is in C# and I'm proficient in it, so importing libraries is no problem. I actually thought that Unity didn't allow it for some reason, but I guess it does (useful knowledge in itself).
     
  6. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Personally, I think that's one of the really cool features of Unity: It's using Mono, and Mono is "pretty much" equivalent with .NET. They're lagging behind a bit with versions (for example, while the Mono version that's used in 2.1 does have the performance counters APIs, you can't use it because it's not implemented - the interface is there, it compiles but throws runtime exceptions), but you get most of what was available in .NET 2.0.

    Hopefully, they'll migrate to the most current version of Mono soon, because there have been a lot of improvements to Mono meanwhile.