纳金网

标题: 求大神教一下关于u3d网络连接的问题! [打印本页]

作者: 她。    时间: 2012-9-4 09:37
标题: 求大神教一下关于u3d网络连接的问题!
最近在研究u3d的网络连接小弟看了几遍H2M的网络连接demo和另外的一些网络demo.但还是有很多不明白的地方,希望大神教一下

比如,这个就是创建了一个主机的意思吧,主机游戏名为JohnDoes game,游戏type名为MyUniqueGameType.

复制代码


    if(GUI.Button(new Rect(10,50,100,30),"Start Server"))
        {
            Network.useNat=userNAT;
            Network.InitializeServer(32,listenPort);
            MasterServer.RegisterHost("MyUniqueGameType","JohnDoes game", "l33t game for all");
        }






这个就是点击Refresh按钮,然后是刷新主机的吧.但是为什么检测不主机出来呢?请教大神教一下~

复制代码


    if(GUI.Button(new Rect(10,90,100,30),"Refresh"))
                {
                    MasterServer.ClearHostList();
                    MasterServer.RequestHostList("MyUniqueGameType");
                    HostData[] hostData = MasterServer.PollHostList();
                    int i = 0;
                    while (i < hostData.Length)
                    {
                        string names=hostData.gameName+" "+hostData.ip;
                        if(GUI.Button(new Rect(50,100+i*40,100,30),names))
                        {
                            Network.Connect(hostData);
                        }
                        //Debug.Log("Game name: " + hostData.gameName);
                        i++;
                    }
                }


作者: 艾西格亚    时间: 2012-9-4 14:40
重新检查了一遍,  HostData[] hostData = MasterServer.PollHostList();   这个好像得放在if外面才能检测到,可能是一帧的时间检测不完全

好像在一台机器上不能检测到,如果用2台机器或者和手机连接就能够正确的检测出主机来了 。



if(GUI.Button(new Rect(10,50,100,30),"Start Server"))

            {

                //创建服务器

                Network.useNat=userNAT;

                Network.InitializeServer(32,listenPort);

                MasterServer.RegisterHost(gameName,"JohnDoes game", "l33t game for all");

            }

            

            if(GUI.Button(new Rect(10,90,100,30),"Refresh"))

            {   

                MasterServer.ClearHostList();

                MasterServer.RequestHostList(gameName);

                Debug.Log("Refresh Click");

            }

            HostData[] hostData = MasterServer.PollHostList();

            int i = 0;

            while (i < hostData.Length)

            {

                string[] IPs=hostData.ip;

                foreach(string ip in IPs)

                {

                    if(GUI.Button(new Rect(250,100+i*40,200,30),ip))

                    {

                        Network.Connect(hostData);

                    }

                }

                i++;

            }


作者: 王者再临    时间: 2012-12-30 04:48
学习了,虽然还是有难度,谢谢楼主的用心
作者: 狂风大尉    时间: 2012-12-30 23:41
谢谢楼主的帖子分享,学习了




欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5