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


C# NetClient.DiscoverLocalPeers方法代码示例

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


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

示例1: Connect

        public void Connect()
        {
            client = new NetClient(config);
            client.Start();

            client.DiscoverLocalPeers(14242);
        }
开发者ID:BenMatase,项目名称:RaginRovers,代码行数:7,代码来源:ClientNetworking.cs

示例2: StartDiscoveryInternal

		/// <summary>
		/// 
		/// </summary>
		/// <param name="numPorts"></param>
		/// <param name="timeout"></param>
		void StartDiscoveryInternal ( int numPorts, TimeSpan timeout )
		{
			lock (lockObj) {
				if (client!=null) {
					Log.Warning("Discovery is already started.");
					return;
				}

				this.timeout	=	timeout;

				var netConfig = new NetPeerConfiguration( Game.GameID );
				netConfig.EnableMessageType( NetIncomingMessageType.DiscoveryRequest );
				netConfig.EnableMessageType( NetIncomingMessageType.DiscoveryResponse );

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

				var svPort	=	Game.Network.Port;

				var ports = Enumerable.Range(svPort, numPorts)
							.Where( p => p <= ushort.MaxValue )
							.ToArray();

				Log.Message("Start discovery on ports: {0}", string.Join(", ", ports) );

				foreach (var port in ports) {
					client.DiscoverLocalPeers( port );
				}
			}
		}
开发者ID:demiurghg,项目名称:FusionEngine,代码行数:35,代码来源:UserInterface.Internal.cs

示例3: NetworkMultiplayer

        public NetworkMultiplayer(bool createServer = false)
            : base(GameModes.Network)
        {
            if(createServer)
                GameServer = new GameServer();

            //read network on each update
            Game.Instance.OnUpdate += ReadNetwork;

            //server config
            NetPeerConfiguration config = new NetPeerConfiguration("tank");
            config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);

            //server creation
            Client = new NetClient(config);
            Client.Start();

            if (!createServer)
            {
                //check whether the user has a known server
                ListMenu serverMenu = new ListMenu("Do you want to connect to a given IP (if yes, enter in console)?", "tank.Code.YESORNOCHOOSENOW", ConnectionMethodSelectionCallback);
                Scene.Add(serverMenu);
            }
            else//we know that a local server must exist
                Client.DiscoverLocalPeers(14242);
            //register handler for receiving data
            OnClientData += IncomingHandler;

            //are we client, or are we dancer?
            if(!createServer)
                Console.WriteLine("client");
        }
开发者ID:JOCP9733,项目名称:tank,代码行数:32,代码来源:NetworkMultiplayer.cs

示例4: ServerLayer

        public ServerLayer()
        {
            NetPeerConfiguration config = new NetPeerConfiguration("xnaapp");
            config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);

            client = new NetClient(config);
            client.Start();
            client.DiscoverLocalPeers(14242);
        }
开发者ID:KaptenDavidsson,项目名称:WindowsGame9,代码行数:9,代码来源:ServerLayer.cs

示例5: StartClient

        private void StartClient(int port, string configName)
        {
            var config = new NetPeerConfiguration(configName);
            config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
            Client = new NetClient(config);
            Client.Start();
            Client.DiscoverLocalPeers(port);


        }
开发者ID:umutseven92,项目名称:Romero.Windows,代码行数:10,代码来源:JoinScreen.cs

示例6: 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

示例7: NetworkCliente

        public NetworkCliente(IWorld world, String serverName = "GameServer", int port = 14242, bool waitForConnect = true)
        {
            Debug.Assert(world != null);
            this.world = world;
            NetPeerConfiguration config = new NetPeerConfiguration(serverName);
            config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);

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

            if (waitForConnect)
            {
                waitConnection();
            }

            AddMessageHandler(NetMessageType.CreateNetworkObjectOnClient, RecieveCreateNetworkObjectOnClient);
            AddMessageHandler(NetMessageType.PhysicInternalSync, StartRecieveSyncPhysicMessages);
            AddMessageHandler(NetMessageType.Echo, HandleEchoMessage);

            RegisterMessagePhysicSync(PhysicObjectTypes.SPHEREOBJECT,
                (mes, obj) =>
                {
                    IPhysicObject ent = obj.PhysicObject;
                    ent.Position = mes.ReadVector3();
                    ent.Rotation = Matrix.CreateFromQuaternion(mes.ReadRotation());
                    ent.Velocity = mes.ReadVector3();
                    ent.AngularVelocity = mes.ReadVector3();
                }
            );

            RegisterMessagePhysicSync(PhysicObjectTypes.BOXOBJECT,
                (mes, obj) =>
                {
                    IPhysicObject ent = obj.PhysicObject;
                    ent.Position = mes.ReadVector3();
                    ent.Rotation = Matrix.CreateFromQuaternion(mes.ReadRotation());
                    ent.Velocity = mes.ReadVector3();
                    ent.AngularVelocity = mes.ReadVector3();
                }
            );

            RegisterMessagePhysicSync(PhysicObjectTypes.CYLINDEROBJECT,
                (mes, obj) =>
                {
                    IPhysicObject ent = obj.PhysicObject;
                    ent.Position = mes.ReadVector3();
                    ent.Rotation = Matrix.CreateFromQuaternion(mes.ReadRotation());
                    ent.Velocity = mes.ReadVector3();
                    ent.AngularVelocity = mes.ReadVector3();
                }
            );
        }
开发者ID:brunoduartec,项目名称:port-ploobsengine,代码行数:53,代码来源:NetworkCliente.cs

示例8: Start

        public override void Start()
        {
            if (m_peer != null)
            {
                throw new InvalidOperationException("Client already running");
            }

            NetPeerConfiguration config = new NetPeerConfiguration(m_name);
            config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);

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

            m_peer.DiscoverLocalPeers(m_port);
        }
开发者ID:bbqchickenrobot,项目名称:atomic-bomberman-xna,代码行数:15,代码来源:LocalServersDiscovery.cs

示例9: ImageGetter

        public ImageGetter(string host, NetPeerConfiguration copyConfig)
        {
            InitializeComponent();

            NetPeerConfiguration config = copyConfig.Clone();
            config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);

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

            if (!string.IsNullOrEmpty(host))
            {
                Client.Connect(host, 14242, GetApproveData());
            }
            else
            {
                Client.DiscoverLocalPeers(14242);
            }
        }
开发者ID:cody82,项目名称:spacewar-arena,代码行数:19,代码来源:ImageGetter.cs

示例10: AutoDiscover

        public static void AutoDiscover()
        {
            var config = new NetPeerConfiguration("spacebargame"); // New Lidgren config
            Client = new NetClient(config); // Give NetClient Client our NetPeerConfig config

            NetOutgoingMessage msg = Client.CreateMessage(); // msg is the outgoing message
            Client.Start(); // Boot the client

            Thread.Sleep(500); // Sleep 500

            if (!NetworkingThread.IsAlive)
            {
                Thread NetworkingThread1 = new Thread(NetworkReceive);
                NetworkingThread1.Start(); // Start NetworkingThread for incoming messages.
            }

            Thread.Sleep(500); // Sleep 500
            Client.DiscoverLocalPeers(666);
        }
开发者ID:JamieH,项目名称:SpaceBarGame,代码行数:19,代码来源:Network.cs

示例11: 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

示例12: 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

示例13: 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

示例14: SideScrollGame

        public SideScrollGame(bool isNetworkGame, PlayerColor color, GameplayScreen gameplay)
        {
            main = this;

            gameOver = false;
            allPlayersDead = false;
            allEnemiesDead = false;

            this.gameplay = gameplay;

            currentLevel = 1;

            _goToNextLevel = false;

            _isNetwork = isNetworkGame;

            if (_isNetwork == false)
            {
                isHost = true;
                if (color == PlayerColor.BLUE)
                {
                    player = new Player(gameplay.content.Load<Texture2D>("Character/player"), new Vector2(10, 350));
                }

                Awake();
            }
            else
            {

                NetPeerConfiguration config = new NetPeerConfiguration("robotcontra");
                string localIp = LocalIPAddress();
                config.LocalAddress = IPAddress.Parse(localIp); // disable if there is firewall
                config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);

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

                Thread updateClientsWorld = new Thread(new ThreadStart(getPlayerUpdate));
                updateClientsWorld.Start();

                isFinishWriteLevel = false;

                while (player == null)
                {
                    //getting creating new player
                }
                NetworkAwake();

            }
        }
开发者ID:wuwenhuang,项目名称:RobotContra,代码行数:51,代码来源:SideScrollGame.cs

示例15: Connect

 public void Connect(int port)
 {
     _netClient = new NetClient(_configuration);
     _netClient.RegisterReceivedCallback(HandleMessages);
     _netClient.Start();
     _netClient.DiscoverLocalPeers(port);
 }
开发者ID:jugglingthebits,项目名称:dotnetchat,代码行数:7,代码来源:ChatService.cs


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