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

Please Help - trouble with network script ...

Discussion in 'Multiplayer' started by reset, Jun 14, 2009.

  1. reset

    reset

    Joined:
    May 22, 2009
    Posts:
    393
    I have made a simple chat app - this bit below is the offending code me think. When run the server starts fine - and clients see "chatty" come up - but when the client clicks "connect" nothing happens. :(

    This is a behaviour script attached to a Game Object that also has a Network View attached with State Sync = off and Observed = Nothing.

    Server and Client connect via UT's Master Server.

    Any help would be great!!!!

    thanks


    Code (csharp):
    1. var ChatWindowPos;
    2. var connStat;
    3.  
    4. function Start() {connStat = "No Connection";}
    5.  
    6. function OnGUI(){ConnWindowPos = GUI.Window(1, Rect(301, 0, 200, 280), ConnWindow, "Network Connection");} 
    7.  
    8. @RPC
    9.  
    10. function ConnWindow (windowID : int){
    11.  
    12.         GUILayout.Label(connStat);
    13.  
    14.         if (GUILayout.Button("Start Server")){
    15.             Network.useNat = true;
    16.             Network.InitializeServer(6, 25002);
    17.             MasterServer.RegisterHost("chat", "chatty");
    18.             connStat = "Server Started ...";
    19.         }
    20.        
    21.         if (MasterServer.PollHostList().length != 0) {
    22.             var hostData: HostData[] = MasterServer.PollHostList();
    23.                 for (var i=0; i<hostData.length; i++){
    24.                     GUILayout.Label("Game name: " + hostData[i].gameName);
    25.                     GUILayout.Label("Players: " + hostData[i].connectedPlayers.ToString() + "/" + hostData[i].playerLimit.ToString());
    26.                         if (GUILayout.Button("Connect") ){
    27.                             Network.useNat = true;
    28.                             Network.Connect(hostData[i].ip, hostData[i].port);
    29.                             connStat = "Connecting to Server ...";
    30.                         }
    31.                 }          
    32.  
    33.         }
    34.  
    35.  
    36.         if (GUILayout.Button("Disconnect")){Network.Disconnect();}
    37.     }
    38.  
    39. function OnConnectedToServer() {connStat = "Connected to Server";}
    40.  
    41. function Update() {MasterServer.RequestHostList("chat");}
    :(
     
  2. reset

    reset

    Joined:
    May 22, 2009
    Posts:
    393
    Is the issue due to the "Network.useNat = true;" - I am not declaring the properly?
     
  3. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    useNat should be set accordingly the findings if it is possible at all (see network example in the resource section on the page)

    Other than that, I don't see anything wrong.
    Question is how you decide that something does not work as you don't do anything after connecting other than setting a variable
     
  4. reset

    reset

    Joined:
    May 22, 2009
    Posts:
    393
    Hi Dreamora

    thanks for your reply. This is only part of the script - the other part of the script - not shown here - is for chat.

    However the player count - in Host Data [] - should go up if the connection does happen. Or it should do anyway.

    Also ... "Connected to Server" does not appear on screen to show that the connection has happened.

    This is the site with the final app on it:

    http://tomaengine.sitepages.org/

    You can try it if you want

    thanks[/list]
     
  5. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    tested it and it does not work unlike the network example.
    I guess something thats done is interfering somewhere.
     
  6. reset

    reset

    Joined:
    May 22, 2009
    Posts:
    393
    Hi Dreamora

    did you test it at my site?

    If you take my script and add it to an empty Game Object as behaviour - and then add a Network View to it - Sync = Off - Observed = None - does it work for you?

    This is driving me a bit NUTS!! :)
     
  7. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Used the linked in webplayer and it does not work, while the same for the network example works so at simplest you check where yours differs.
    I would guess its in the connect pre-work
     
  8. reset

    reset

    Joined:
    May 22, 2009
    Posts:
    393
    thanks for your help. I will have to go through it - I am not sure what I could have done wrong - the code and set-up is so simple. :(

    thanks