After looking over the Unity3d website, I have not been able to find a good report on how to use or what proxy is. I ask of the users of the form to please explain it. I hope this may also benefit future users who have the same question.
What is proxy?
What does it require?
How can I implement it to a game?
I do have one script to show: ( I got this from the Resources and Mike Hergaarden’s zero to hero guide)
var imaserver: boolean;
var serverIP = “1.1.1.1”;
var serverPort = 25001;
var serverUsesNAT: boolean;
var Player : Transform;
function Awake()
{
// Set custom proxy server address
Network.proxyIP = serverIP;
Network.proxyPort = serverPort;
}
function OnGUI(){
if (Network.peerType == NetworkPeerType.Disconnected){
//We are currently disconnected: Not a client or host
GUILayout.Label(“Connection status: Disconnected”);
serverIP = GUILayout.TextField(serverIP, GUILayout.MinWidth(100));
serverPort = parseInt(GUILayout.TextField(serverPort.ToString()));
GUILayout.BeginVertical();
if (GUILayout.Button (“Connect as client”))
{
//Connect to the “connectToIP” and “connectPort” as entered via the GUI
//Ignore the NAT for now
ConnectToServerWithProxy();
Network.Instantiate(Player, Vector3.zero, Quaternion.identity, 83);
//Network.useProxy = true;
}
if (GUILayout.Button (“Start Server”))
{
//Start a server for 32 clients using the “connectPort” given via the GUI
//Ignore the nat for now
Network.InitializeServer(32, serverPort);
}
GUILayout.EndVertical();
}else{
//We’ve got a connection(s)!
if (Network.peerType == NetworkPeerType.Connecting){
GUILayout.Label(“Connection status: Connecting”);
} else if (Network.peerType == NetworkPeerType.Client){
GUILayout.Label(“Connection status: Client!”);
GUILayout.Label("Ping to server: "+Network.GetAveragePing( Network.connections[0] ) );
} else if (Network.peerType == NetworkPeerType.Server){
GUILayout.Label(“Connection status: Server!”);
GUILayout.Label("Connections: "+Network.connections.length);
if(Network.connections.length==1){
GUILayout.Label("Ping to first player: "+Network.GetAveragePing( Network.connections[0] ) );
}
if(Network.connections.length==2){
GUILayout.Label("Ping to second player: "+Network.GetAveragePing( Network.connections[1] ) );
}
}
if (GUILayout.Button (“Disconnect”))
{
Network.Disconnect(200);
}
}
}
if (imaserver)
{
StartServerWithProxy();
}
else
{
ConnectToServerWithProxy();
}
function StartServerWithProxy()
{
Network.useProxy = true;
Network.InitializeServer(32 ,Network.proxyPort);
}
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.useNat = serverUsesNAT;
Network.Connect(serverIP, serverPort);
}
function OnConnectedToServer()
{
Debug.Log(“Connected successfully to server”);
}