Beispiel #1
0
        /// <summary>
        /// Enable to connect to a server
        /// </summary>
        /// <param name="server">Server.</param>
        public static void connectTo(string server, string user)
        {
            userName = user;
            int port = 20336;
            string ipServer = server;

            // parse to have the server IP and Port
            if (server.Contains (":")) {
                string[] serverSplited = server.Split (':');
                ipServer = serverSplited [0];
                port = int.Parse (serverSplited [1]);
            }

            // initialize the connection, after 2s to wait, it is concidered
            // that the server does not respond
            ConnexionUtils.host.InitializeClient (1);
            ConnexionUtils.peer = ConnexionUtils.host.Connect (ipServer, port, 0, 2);
            if (ConnexionUtils.host.Service (2000, out ConnexionUtils.@event)) {
                if (ENet.EventType.Connect == [email protected]) {
                    ConnexionUtils.connected = true;
                    Debug.Log ("Connected to server at IP/port " + peer.GetRemoteAddress ());
                }
            } else {
                Debug.LogError ("Problème de connexion, met plus de 2s à répondre");
                peer.Disconnect (0);
                host.Dispose ();
            }
        }