Indicate if proxy support is needed, in which case traffic is relayed through the proxy server.
var imaserver: boolean; var serverIP: String; var serverPort: int; var serverUsesNAT: boolean; function Awake() { // Set custom proxy server address Network.proxyIP = "1.1.1.1"; Network.proxyPort = 1111; if (imaserver) StartServerWithProxy(); else ConnectToServerWithProxy(); } function StartServerWithProxy() { Network.useProxy = true; Network.InitializeServer(2,25000, false); } function OnServerInitialized(player: NetworkPlayer) { if (Network.useProxy) Debug.Log ("Successfully started server with proxy support. We are connectable through " + player.ipAddress + ":" + player.port); } function OnFailedToConnect(msg: NetworkConnectionError) { if (Network.useProxy && imaserver) { Debug.LogError("Failed to connect to proxy server: " + msg); } } function ConnectToServerWithProxy() { Network.useProxy = true; Network.Connect(serverIP, serverPort); } function OnConnectedToServer() { Debug.Log("Connected successfully to server"); }
using UnityEngine; using System.Collections; public class Example : MonoBehaviour { public bool imaserver; public string serverIP; public int serverPort; public bool serverUsesNAT; void Awake() { Network.proxyIP = "1.1.1.1"; Network.proxyPort = 1111; if (imaserver) StartServerWithProxy(); else ConnectToServerWithProxy(); } void StartServerWithProxy() { Network.useProxy = true; Network.InitializeServer(2, 25000, false); } void OnServerInitialized(NetworkPlayer player) { if (Network.useProxy) Debug.Log("Successfully started server with proxy support. We are connectable through " + player.ipAddress + ":" + player.port); } void OnFailedToConnect(NetworkConnectionError msg) { if (Network.useProxy && imaserver) Debug.LogError("Failed to connect to proxy server: " + msg); } void ConnectToServerWithProxy() { Network.useProxy = true; Network.Connect(serverIP, serverPort); } void OnConnectedToServer() { Debug.Log("Connected successfully to server"); } }
import UnityEngine import System.Collections public class Example(MonoBehaviour): public imaserver as bool public serverIP as string public serverPort as int public serverUsesNAT as bool def Awake() as void: Network.proxyIP = '1.1.1.1' Network.proxyPort = 1111 if imaserver: StartServerWithProxy() else: ConnectToServerWithProxy() def StartServerWithProxy() as void: Network.useProxy = true Network.InitializeServer(2, 25000, false) def OnServerInitialized(player as NetworkPlayer) as void: if Network.useProxy: Debug.Log(((('Successfully started server with proxy support. We are connectable through ' + player.ipAddress) + ':') + player.port)) def OnFailedToConnect(msg as NetworkConnectionError) as void: if Network.useProxy and imaserver: Debug.LogError(('Failed to connect to proxy server: ' + msg)) def ConnectToServerWithProxy() as void: Network.useProxy = true Network.Connect(serverIP, serverPort) def OnConnectedToServer() as void: Debug.Log('Connected successfully to server')