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


C# NetClient.DiscoverLocalServers方法代码示例

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


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

示例1: ImageClient

		public ImageClient()
		{
			InitializeComponent();

			NetConfiguration config = new NetConfiguration("imageservice");
			m_client = new NetClient(config);
			m_client.SimulatedMinimumLatency = 0.05f;

			m_readBuffer = m_client.CreateBuffer();

			m_client.DiscoverLocalServers(14242);

			this.FormClosed += new FormClosedEventHandler(OnClosed);
			this.Show();
		}
开发者ID:marvel54,项目名称:lidgren-network,代码行数:15,代码来源:ImageClient.cs

示例2: Main

		static void Main(string[] args)
		{
			// create a client with a default configuration
			NetConfiguration config = new NetConfiguration("chatApp");
			NetClient client = new NetClient(config);
			client.SetMessageTypeEnabled(NetMessageType.ConnectionRejected, true);
			client.SetMessageTypeEnabled(NetMessageType.DebugMessage, true);
			//client.SetMessageTypeEnabled(NetMessageType.VerboseDebugMessage, true);
			client.Start();

			// Wait half a second to allow server to start up if run via Visual Studio
			Thread.Sleep(500);

			// Emit discovery signal
			client.DiscoverLocalServers(14242);

			// create a buffer to read data into
			NetBuffer buffer = client.CreateBuffer();

			// current input string
			string input = "";

			// keep running until the user presses a key
			Console.WriteLine("Type 'quit' to exit client");
			Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);
			s_keepGoing = true;
			while (s_keepGoing)
			{
				NetMessageType type;

				// check if any messages has been received
				while (client.ReadMessage(buffer, out type))
				{
					switch (type)
					{
						case NetMessageType.ServerDiscovered:
							// just connect to any server found!

							// make hail
							NetBuffer buf = client.CreateBuffer();
							buf.Write("Hail from " + Environment.MachineName);
							client.Connect(buffer.ReadIPEndPoint(), buf.ToArray());
							break;
						case NetMessageType.ConnectionRejected:
							Console.WriteLine("Rejected: " + buffer.ReadString());
							break;
						case NetMessageType.DebugMessage:
						case NetMessageType.VerboseDebugMessage:
							Console.WriteLine(buffer.ReadString());
							break;
						case NetMessageType.StatusChanged:
							string statusMessage = buffer.ReadString();
							NetConnectionStatus newStatus = (NetConnectionStatus)buffer.ReadByte();
							Console.WriteLine("New status: " + newStatus + " (" + statusMessage + ")");
							break;
						case NetMessageType.Data:
							// The server sent this data!
							string msg = buffer.ReadString();
							Console.WriteLine(msg);
							break;
					}
				}

				while (Console.KeyAvailable)
				{
					ConsoleKeyInfo ki = Console.ReadKey();
					if (ki.Key == ConsoleKey.Enter)
					{
						if (!string.IsNullOrEmpty(input))
						{
							if (input == "quit")
							{
								// exit application
								s_keepGoing = false;
							}
							else
							{
								// Send chat message
								NetBuffer sendBuffer = new NetBuffer();
								sendBuffer.Write(input);
								client.SendMessage(sendBuffer, NetChannel.ReliableInOrder1);
								input = "";
							}
						}
					}
					else
					{
						input += ki.KeyChar;
					}
				}

				Thread.Sleep(1);
			}

			client.Shutdown("Application exiting");
		}
开发者ID:marvel54,项目名称:lidgren-network,代码行数:96,代码来源:Program.cs


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