当前位置: 首页>>代码示例>>C#>>正文


C# NetClient.DiscoverKnownPeer方法代码示例

本文整理汇总了C#中Lidgren.Network.NetClient.DiscoverKnownPeer方法的典型用法代码示例。如果您正苦于以下问题:C# NetClient.DiscoverKnownPeer方法的具体用法?C# NetClient.DiscoverKnownPeer怎么用?C# NetClient.DiscoverKnownPeer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lidgren.Network.NetClient的用法示例。


在下文中一共展示了NetClient.DiscoverKnownPeer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Load

        public override void Load()
        {
            bgContainer = new Sprite();
            bgLayers = new Sprite[3];
            AddChild(bgContainer);
            for (int i = 0; i < 3; ++i)
            {
                bgLayers[i] = new Sprite();

                var bmp1 = new Bitmap(Assets.GetBitmapData("assets/background/1/" + (i + 1).ToString(), true));
                var bmp2 = new Bitmap(Assets.GetBitmapData("assets/background/1/" + (i + 1).ToString(), true));

                bmp2.X = bmp1.Width;

                bgLayers[i].AddChild(bmp1);
                bgLayers[i].AddChild(bmp2);

                bgContainer.AddChild(bgLayers[i]);
            }
            // GUI
            guiContainer = new Sprite();
            AddChild(guiContainer);

            NetPeerConfiguration config = new NetPeerConfiguration("multiplanes-network");
            client = new NetClient(config);
            client.Start();
            client.DiscoverLocalPeers(14242);
            client.DiscoverKnownPeer(GameClient.NET_ADRESS, GameClient.NET_PORT);

            nick = NickGenerator.GenerateNick(client.UniqueIdentifier);

            var screenNameLabel = new TextField();
            screenNameLabel.font = Assets.GetFont("assets/MainFont");
            screenNameLabel.text = "HOST GAME";
            screenNameLabel.X = GameMain.ScreenWidth / 2 - screenNameLabel.Width / 2;
            screenNameLabel.Y = 10 / GameMain.mainScale;
            guiContainer.AddChild(screenNameLabel);

            var roomNameLabel = new TextField();
            roomNameLabel.font = screenNameLabel.font;
            roomNameLabel.text = "Room name: " + nick;
            roomNameLabel.X = GameMain.ScreenWidth * 0.1f;
            roomNameLabel.Y = GameMain.ScreenHeight / 2 - roomNameLabel.Height / 2;
            roomNameLabel.ScaleX = roomNameLabel.ScaleY = 0.5f;
            guiContainer.AddChild(roomNameLabel);

            waitLabel = new TextField();
            waitLabel.font = roomNameLabel.font;
            waitLabel.text = "Waiting for other player to connect. . .";
            waitLabel.X = roomNameLabel.X;
            waitLabel.Y = roomNameLabel.Y + roomNameLabel.Height;
            waitLabel.ScaleX = waitLabel.ScaleY = 0.25f;
            guiContainer.AddChild(waitLabel);
        }
开发者ID:Morozov-5F,项目名称:monoflash-planes-game,代码行数:54,代码来源:HostGameScreen.cs

示例2: checkButtons

        bool checkButtons()
        {
            if (createButton.Triggered)
            {
                cleanup();
                returnControl("create");
                return true;
            }
            else if (joinLanButton.Triggered)
            {
                NetPeerConfiguration config = new NetPeerConfiguration("rts");
                config.Port = 14243;

                client = new NetClient(config);
                client.Start();

                //client.Configuration.SimulatedMinimumLatency = .5f;
                //client.Configuration.SimulatedRandomLatency = .01f;

                client.DiscoverLocalPeers(14242);

                state = StartMenuState.Joining;
            }
            else if (joinIPButton.Triggered)
            {
                if (!File.Exists("C:\\rts hosts.txt"))
                    File.Create("C:\\rts hosts.txt");

                string[] hosts = File.ReadAllLines("C:\\rts hosts.txt");

                NetPeerConfiguration config = new NetPeerConfiguration("rts");
                config.Port = 14243;

                client = new NetClient(config);
                client.Start();

                //client.Configuration.SimulatedMinimumLatency = .5f;
                //client.Configuration.SimulatedRandomLatency = .01f;

                foreach (string host in hosts)
                    client.DiscoverKnownPeer(host, 14242);

                state = StartMenuState.Joining;
            }
            else if (exitButton.Triggered)
            {
                cleanup();
                returnControl("exit");
                return true;
            }

            return false;
        }
开发者ID:nubington,项目名称:rts,代码行数:53,代码来源:StartMenu.cs

示例3: Load

        public override void Load()
        {
            // Background
            bgContainer = new Sprite();
            bgLayers = new Sprite[3];
            AddChild(bgContainer);
            for (int i = 0; i < 3; ++i)
            {
                bgLayers[i] = new Sprite();

                var bmp1 = new Bitmap(Assets.GetBitmapData("assets/background/1/" + (i + 1).ToString(), true));
                var bmp2 = new Bitmap(Assets.GetBitmapData("assets/background/1/" + (i + 1).ToString(), true));

                bmp2.X = bmp1.Width;

                bgLayers[i].AddChild(bmp1);
                bgLayers[i].AddChild(bmp2);

                bgContainer.AddChild(bgLayers[i]);
            }
            // GUI
            guiContainer = new Sprite();
            AddChild(guiContainer);

            hosts = new List<HostLabel>();

            font = Assets.GetFont("assets/MainFont");

            var screenNameLabel = new TextField();
            screenNameLabel.font = font;
            screenNameLabel.text = "JOIN GAME";
            screenNameLabel.X = GameMain.ScreenWidth / 2 - screenNameLabel.Width / 2;
            screenNameLabel.Y = 10 / GameMain.mainScale;
            guiContainer.AddChild(screenNameLabel);

            pointerLabel = new TextField();
            pointerLabel.font = screenNameLabel.font;
            pointerLabel.text = "Select a game to join";
            pointerLabel.ScaleX = pointerLabel.ScaleY = 0.4f;
            pointerLabel.X = GameMain.ScreenWidth / 2 - pointerLabel.Width / 2;
            pointerLabel.Y = screenNameLabel.Y + screenNameLabel.Height;
            guiContainer.AddChild(pointerLabel);

            connectButton = new TextField();
            connectButton.font = font;
            connectButton.text = "Connect";
            connectButton.ScaleX = connectButton.ScaleY = 0.5f;
            connectButton.X = GameMain.ScreenWidth * 0.25f - connectButton.Width / 2;
            connectButton.Y = GameMain.ScreenHeight - connectButton.Height;
            connectButton.textColor = Color.DarkGray;
            guiContainer.AddChild(connectButton);

            refreshButton = new TextField();
            refreshButton.font = font;
            refreshButton.text = "Refresh";
            refreshButton.ScaleX = refreshButton.ScaleY = 0.5f;
            refreshButton.X = GameMain.ScreenWidth * 0.75f - refreshButton.Width / 2;
            refreshButton.Y = connectButton.Y;
            guiContainer.AddChild(refreshButton);

            connectButton.AddEventListener(Event.TOUCH_END, onButtonDown);
            refreshButton.AddEventListener(Event.TOUCH_END, onButtonDown);

            NetPeerConfiguration config = new NetPeerConfiguration("multiplanes-network");
            client = new NetClient(config);
            client.Start();
            nick = NickGenerator.GenerateNick((client.UniqueIdentifier));
            client.DiscoverLocalPeers(14242);
            client.DiscoverKnownPeer(GameClient.NET_ADRESS, GameClient.NET_PORT);
        }
开发者ID:Morozov-5F,项目名称:monoflash-planes-game,代码行数:70,代码来源:JoinGameScreen.cs

示例4: Connect

        public void Connect()
        {
            if (netClient != null && netClient.Status == NetPeerStatus.Running)
                return;

            isConnected = false;

            netConfig.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);

            // Create a client
            netClient = new NetClient(netConfig);
            netClient.Start();

            try
            {
                if (waitForServer)
                {
                    Thread connectionThread = new Thread(new ThreadStart(TryConnect));
                    connectionThread.Start();
                }
                else
                {
                    if (isLocalAddress)
                        netClient.DiscoverLocalPeers(portNumber);
                    else
                        netClient.DiscoverKnownPeer(hostPoint);
                }
            }
            catch (SocketException se)
            {
                Log.Write("Socket exception is thrown in Connect: " + se.StackTrace);
            }
        }
开发者ID:NinjaSteph,项目名称:SureShot,代码行数:33,代码来源:LidgrenClient.cs

示例5: Load

        public void Load()
        {
            isFinished = false;

            // create client configuration
            clientConfig = new NetPeerConfiguration("pacman");
            //configure client
            client = new NetClient(clientConfig);
            //Start client
            client.Start();

            if (client != null)
            {
                NetIncomingMessage msg;
                bool waitingForServer = true;

                // Contact Server
                client.DiscoverKnownPeer("localhost", 666);
                //client.DiscoverLocalPeers(666);

                while (waitingForServer)
                {
                    while ((msg = client.ReadMessage()) != null)
                    {
                        switch (msg.MessageType)
                        {
                            case NetIncomingMessageType.DiscoveryResponse:
                                try
                                {
                                    client.Connect(msg.SenderEndpoint);
                                    //waitingForServer = false;
                                }
                                catch (Exception e)
                                {
                                    System.Console.WriteLine(e.ToString());
                                    //waitingForServer = false;
                                }
                                break;
                            case NetIncomingMessageType.Data:
                                if (msg.ReadString() == "connected")
                                {
                                    waitingForServer = false;
                                }
                                break;
                        }
                    }

                    if (timeoutCount > timeoutLimit)
                    {
                        waitingForServer = false;
                    }
                    double elapsedTime = gameTime.ElapsedGameTime.TotalMilliseconds;
                    timeoutCount += elapsedTime;
                }
            }

            foreach (GameScreen screen in gameScreens)
            {
                if (screen is ConfigMultiplayerScreen)
                {
                    //((ConfigMultiplayerScreen)screen).setClient(client);
                    //((ConfigMultiplayerScreen)screen).setConntectedServer(client.ServerConnection.RemoteEndpoint.Address.ToString());
                }
                screenManager.AddScreen(screen, PlayerIndex.One);
            }

            isFinished = true;
        }
开发者ID:Rosthouse,项目名称:Multi-Pac,代码行数:68,代码来源:ConnectServerLoader.cs


注:本文中的Lidgren.Network.NetClient.DiscoverKnownPeer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。