unity NAT tech, MasterServer sample

February 13, 2013   ·   0 Comments

Screen Shot 2013-02-13 at 12.03.09 PM

Screen Shot 2013-02-13 at 12.03.09 PM

using UnityEngine;
using System.Collections;

public class networkClass : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	
	private bool isClientWorking=false;
	
	void OnGUI() {
		
			
			 if (GUILayout.Button ("Start Server")) {
			        // Use NAT punchthrough if no public IP present
			        var useNat = !Network.HavePublicAddress();
			        Network.InitializeServer(32, 25002, useNat);
			        MasterServer.RegisterHost("PowenKoGame", 
			            "PowenKo Server1", "l33t game for all");
    		}
			
		
		if (GUILayout.Button ("Start Client"))
		{
				
			MasterServer.ClearHostList();
	        MasterServer.RequestHostList("MyUniqueGameType");		
		
		}
		
			
        if (MasterServer.PollHostList().Length != 0) {
            HostData[] hostData = MasterServer.PollHostList();
            int i = 0;
            while (i < hostData.Length) {
					GUI.Button(new Rect(100,10*i,100,100),"Game name: " + hostData[i].gameName);
                i++;
            }
        }
		
		
	}    
	
	
}

shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Unity3D4

Amazon

adsbygoogle

Recent Posts

Categories

Amazon