Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Struggling with multiplayer iPhone connections

Discussion in 'iOS and tvOS' started by The-Scripter, Sep 13, 2011.

  1. The-Scripter

    The-Scripter

    Joined:
    Nov 10, 2009
    Posts:
    30
    I’m hoping someone who understands multiplayer on the iPhone can clarify a couple of questions that the docs and tutorials have missed. I have been working on and testing Networking options with the iPhone for several days but some things are still unclear. I have been able to start a working direct connection by typing in the server’s IP address but nothing more sophisticated.

    Using iOS devices, can Unity Networking make games playable across a specific wireless LAN, i.e. playing with people in the same building, as well as across the wider internet? If it can, what connection methods do I need to use to build both modes?

    Is the Master Server an application on Unity’s server that our game servers connect to or will it be running on one of the devices running my game

    Will we need a dedicated server supporting the game, or will a player create a game and become the server?

    The example project tries to help with iPhone multiplayer connections, but it is out of date so doesn’t work, and the “tutorial” that comes with it is mostly a list of instructions, frustratingly with no explanation as to how is is supposed to work.

    If anyone could answer any of these questions I would be grateful, and I hope it will help other users in my position too.
     
  2. squidbot

    squidbot

    Joined:
    Jan 4, 2011
    Posts:
    128
    A couple quick answers. First off, spring for the M2H tutorial: http://forum.unity3d.com/threads/29015-UniKnowledge-entry-Unity-Networking-the-Zero-to-Hero-guide

    It's up to date and actually covers practical issues you'll need to be aware of.

    You have the choice of running a dedicated server, but you can also do peer to peer. The trick with peer to peer is that if you want to reach the wider internet, you'll still need a server running, but its a special type of server Unity provides which is called a proxy server. This is used to facilitate communication when peer to peer NAT traversal isn't possible (for example, anything involving AT&T 3G will need to go through a proxy as AT&T uses asymmetric randomized NAT). This server can easily be stood up on AWS, Rackspace or the like.

    There's also a "connection tester" server, Unity offers a public one, though it's really slow, which can look for different ways to do NAT traversal, but in practice we've found it only works for some very edge conditions, so it's not worth the extra hassle and slow connection times.

    If you are only allowing local LAN play, then you don't need to worry about the proxy, peer to peer should just connect, unless the player has a really unusual LAN setup, but this would be an edge case.
     
  3. flamy

    flamy

    Joined:
    Feb 7, 2011
    Posts:
    194
    1) here it doesnt matter if u r playing on lan or internet, u jus need the ipadress of the peer u wanna connect to. u need not take care of mode of data transfer, unity will. u may have to write 3 -4 lines of code to run ur game in both online and offline.

    2) master server is an application run on a remote ip by unity for the users to test the networking facility ( still it is reliable for commercial, atleast for me). u can run ur own master server if u want, unity provides all neccessary sources for free.

    3) Dedicated server is just an option. it is not necessary that a server shd be dedicated to run ur game. mostly it depends on ur game. i dont think an iphone game would need a dedicated server :)P). usualy the peer that host becomes the server and all others connecting to it are clients( thts the basic of a network).

    4) If u think connecting with ipaddress is not good just use master server, which will make ur work regarding connections simple.

    5) Regarding tutorial follow the http://forum.unity3d.com/threads/29015-UniKnowledge-entry-Unity-Networking-the-Zero-to-Hero-guide first. And then whn u come back to unity tutorial u will find everything simple( most probally u dont have to come back)
    if the download link in the above link is not working try this http://www.4shared.com/document/Lz4dhIww/M2H_Networking_Tutorial.html

    tutorial source code: http://www.4shared.com/file/brbrs0j5/M2H_Networking_Tutorial.html


    Feel free to drop a PM if u need something :)
     
    Last edited: Sep 13, 2011
  4. The-Scripter

    The-Scripter

    Joined:
    Nov 10, 2009
    Posts:
    30
    Thanks for your help and those links. I’ve looked at the old version of the M2H tutorial, and I’m hoping we will be able to buy the up-to-date one from the asset store. Networking makes a lot more sense now!

    But 1 thing that I still haven’t been able to overcome is the connection test always returns an error, followed by the error message “Failed to connect to master server at...[public IP]” Is this something to do with NAT settings?