3
\$\begingroup\$

I am creating a game in Unity and I would like to create an ability for players to join the game that others have created on the same wifi. I would like it to be as effortless as possible(e.g. players don't have to find out their wifi, etc). The game is cross-platform - you could have one player on PC, other on Android device, etc.

Now I know that there is a game that has similar mechanism to what I would like to achieve: SpaceTeam. Basically you select whether you use BT or wifi, and wait for other players to join.

How can I do this in Unity, or something similar that satisfies my needs?

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

A UDP datagram sent to the broadcast address is delivered to all nodes on the LAN.

I don't normally do networking in C# but it should go something like this: First, listen for packets with any destination address.

new IPEndPoint(IPAddress.Any, ...)

Now, send packets to the broadcast address:

new IPEndPoint(IPAddress.Broadcast, ...)

These packets will be received by every machine behind the same router, via WiFi or Ethernet.

\$\endgroup\$
3
  • \$\begingroup\$ It would be far more elegant to find a solution with the Unity networking system, becaues that would integrate far better with the rest of the engine. \$\endgroup\$
    – Philipp
    Jul 10, 2016 at 23:10
  • \$\begingroup\$ Give a man a fish, and you feed him for a day. Teach a man to fish, and you feed him for a lifetime. \$\endgroup\$
    – MickLH
    Jul 11, 2016 at 0:16
  • \$\begingroup\$ You're always free to post a Unity specific answer, though! \$\endgroup\$
    – MickLH
    Jul 11, 2016 at 0:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .