Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Network.Connect(IP, Port); won't work.

Discussion in 'Multiplayer' started by The-Game-Master, Aug 24, 2014.

  1. The-Game-Master

    The-Game-Master

    Joined:
    Aug 6, 2014
    Posts:
    54
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Network1 : MonoBehaviour {
    5.     // Use this for initialization
    6.     void Start () {
    7.     }
    8.    
    9.     // Update is called once per frame
    10.     void Update () {
    11.     }
    12.  
    13.     void OnGUI() {
    14.         Debug.Log ("OnGUI()");
    15.         if (Network.peerType == NetworkPeerType.Disconnected){
    16.                if (GUI.Button (new Rect(10, 30, 120, 20), "Join a game")){
    17.                     Network.Connect("localhost", 25001);
    18.             }
    19.             if (GUI.Button (new Rect(10, 50, 120, 20), "Host a game")){
    20.                 Network.InitializeServer(32, 25001, true);
    21.             }
    22.             else if (Network.peerType == NetworkPeerType.Client){
    23.                 GUI.Label(new Rect(10, 10, 300, 20), "Status: Connected as a Client");
    24.                 if (GUI.Button (new Rect(10, 30, 120, 20), "Leave lobby")){
    25.                     Network.Disconnect(200);
    26.                 }
    27.             }
    28.         }
    29.         if (Network.isServer)
    30.         {
    31.             Debug.Log (Network.connections);
    32.         }
    33.     }
    34. }
    I have some code, and I host the game on one app (Unity Editor), then join the game (try anyway) in an executable. This is my code, and when I click "Join game", it doesn't join, and the host doesn't show that it has any clients.
     
  2. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
  3. The-Game-Master

    The-Game-Master

    Joined:
    Aug 6, 2014
    Posts:
    54