Search Unity

Networking help

Discussion in 'Multiplayer' started by RPGKHFan, Dec 30, 2008.

  1. RPGKHFan

    RPGKHFan

    Joined:
    Dec 29, 2008
    Posts:
    51
    I read the networking guide from beginning to end and understand all the concepts. The problem I have is that I don't understand how it fits together. Is there a tutorial in which you actual create a networking game or something like that? I tried to make a networking game with what I knew, but for some reason no one could connect... If there isn't one, could someone make one, or try to explain it to me? Thanks for an help in advanced.
     
  2. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
  3. RPGKHFan

    RPGKHFan

    Joined:
    Dec 29, 2008
    Posts:
    51
    Ok, I'll look up the networking examples. I am gonna have to find out how to run Unity twice, though.
     
  4. Tempest

    Tempest

    Joined:
    Dec 10, 2008
    Posts:
    1,286
    File->Build.
    You can build the project as a web player, or standalone. If you build as a web player you can open it in multiple browser windows.
     
  5. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    You can also start the game from the console (which I find the most convenient way of starting up multiple instances) or use "right-click/show package contents" and then go down to Contents/MacOS/<yourGameName> - double click on that as often as you want the game to come up.

    Oh, also you can do "build run" a couple of times to start a couple of instances of your game.

    Opening the editor two times ... hm ... I did that for a while but ended up not being sure if I severely broke something, so I wouldn't recommend it (and if you still want to do it - make a copy of your project and make a copy of Unity and then make sure you don't "cross the streams" ;-) ).
     
  6. RPGKHFan

    RPGKHFan

    Joined:
    Dec 29, 2008
    Posts:
    51
    Hi,
    I tried to make a networking demo. All it is supposed to do is create a server on the master server and verify if it's there. For some reason, when I run it, I get the "AAAGH! ERROR!!!" printed on the screen. Did I register my server wrong? It detects no servers, but it doesn't seem to create on right. Any help? Also, I will just use build and run, I was trying to use multiple Unity's and it was all weirdness. I tested this code just be running it in Unity, no multiple clients or anything.
    Here is the code:
    Code (csharp):
    1. var GameType : String;
    2. var DefaultGameName : String;
    3. var DefaultDescription : String;
    4. function Awake() {
    5.     // Make sure list is empty and request a new list
    6.     MasterServer.ClearHostList();
    7.     MasterServer.RequestHostList(GameType);
    8. }
    9.  
    10. function Update() {
    11.     // If any hosts were received, display game name, the clear host list again
    12.     if (MasterServer.PollHostList().length != 0) {
    13.         var hostData: HostData[] = MasterServer.PollHostList();
    14.         for (var i:int=0; i<hostData.length; i++) {
    15.             Debug.Log("Game name: " + hostData[i].gameName);
    16.         }
    17.         MasterServer.ClearHostList();
    18.     } else {
    19.         Network.useNat = !Network.HavePublicAddress();
    20.         Network.InitializeServer(32, 25002);
    21.         MasterServer.RegisterHost(GameType, DefaultGameName, "TDM "+DefaultDescription);
    22.     }
    23.     if (MasterServer.PollHostList().length != 0) {
    24.         hostData = MasterServer.PollHostList();
    25.         for (i=0; i<hostData.length; i++) {
    26.             Debug.Log("Game name: " + hostData[i].gameName);
    27.         }
    28.         MasterServer.ClearHostList();
    29.     } else {
    30.         Debug.Log("AAAGH! ERROR!!!");
    31.     }  
    32. }
    Thanks for any help in advanced.
     
  7. Tempest

    Tempest

    Joined:
    Dec 10, 2008
    Posts:
    1,286
    I am working on some flow charts for how the Networking demo works. I looked it over for a couple hours and then decided mapping out the flow of all the function calls would be a good idea.

    When I'm done drawing them out in OpenOffice, I'll PDF it and post a link. It helps a lot to see how this stuff works. I'm a newbie with networking, but it's my top priority, so I'm diving into it :)
     
  8. Sanity11

    Sanity11

    Joined:
    Nov 25, 2007
    Posts:
    96
    That would be great Tempest!