public void AgentConnect(ConnectionString connection) { // Disconnect from current server if (IsConnected) { TNManager.Disconnect(); } TNManager.Connect(connection.IP, connection.Port); }
/// <summary> /// Connect to the server. /// </summary> public void Connect() { // We don't want mobile devices to dim their screen and go to sleep while the app is running Screen.sleepTimeout = SleepTimeout.NeverSleep; // Make it possible to use UDP using a random port TNManager.StartUDP(Random.Range(10000, 50000)); // Connect to the remote server TNManager.Connect(serverAddress, serverPort); }
void Connect(IPEndPoint extAddress, IPEndPoint intAddress) { if (string.IsNullOrEmpty(playerName.text)) { mMessage = "Player Name Required."; return; } TNManager.playerName = playerName.text; Debug.LogFormat("connecting to ext: {0} int: {1}", extAddress, intAddress); TNManager.Connect(extAddress, intAddress); mMessage = "Connecting..."; }
/// <summary> /// This menu is shown if the client has not yet connected to the server. /// </summary> void DrawConnectMenu() { Rect rect = new Rect(Screen.width * 0.5f - 200f * 0.5f - mAlpha * 120f, Screen.height * 0.5f - 100f, 200f, 220f); // Show a half-transparent box around the upcoming UI GUI.color = new Color(1f, 1f, 1f, 0.5f); GUI.Box(UnityTools.PadRect(rect, 8f), ""); GUI.color = Color.white; GUILayout.BeginArea(rect); { GUILayout.Label("Server Address", text); mAddress = GUILayout.TextField(mAddress, input, GUILayout.Width(200f)); if (GUILayout.Button("Connect", button)) { // We want to connect to the specified destination when the button is clicked on. // "OnNetworkConnect" function will be called sometime later with the result. TNManager.Connect(mAddress); mMessage = "Connecting..."; } if (TNServerInstance.isActive) { GUI.backgroundColor = Color.red; if (GUILayout.Button("Stop the Server", button)) { // Stop the server, saving all the data TNServerInstance.Stop("server.dat"); mMessage = "Server stopped"; } } else { GUI.backgroundColor = Color.green; if (GUILayout.Button("Start a Local Server", button)) { #if UNITY_WEBPLAYER mMessage = "Can't host from the Web Player due to Unity's security restrictions"; #else int udpPort = Random.Range(10000, 40000); // Start a local server, loading the saved data if possible // The UDP port of the server doesn't matter much as it's optional, // and the clients get notified of it via Packet.ResponseSetUDP. TNUdpLobbyClient lan = GetComponent <TNUdpLobbyClient>(); int lobbyPort = (lan != null) ? lan.remotePort : 0; TNServerInstance.Start(serverTcpPort, udpPort, "server.dat", lobbyPort); mMessage = "Server started"; #endif } } GUI.backgroundColor = Color.white; if (!string.IsNullOrEmpty(mMessage)) { GUILayout.Label(mMessage, text); } } GUILayout.EndArea(); if (mAlpha > 0.01f) { rect.x = rect.x + (Screen.width - rect.xMin - rect.xMax) * mAlpha; DrawServerList(rect); } }
private void button_connect_onClick() { button_connect.interactable = false; TNManager.Connect(connectIp, connectPort); }