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


C# NetServer.SetMessageTypeEnabled方法代码示例

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


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

示例1: NetServerWrapper

        public NetServerWrapper(NetServer netServer)
        {
            _netServer = netServer;

            //_netServer.Simulate(0.1f, 0.1f, 0.2f, 0.1f);

            _netServer.SetMessageTypeEnabled(NetMessageType.ConnectionApproval, true);
#if DEBUG
            _netServer.SetMessageTypeEnabled(NetMessageType.VerboseDebugMessage, true);
#endif

        }
开发者ID:zakvdm,项目名称:Frenetic,代码行数:12,代码来源:NetServerWrapper.cs

示例2: Main

        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            s_mainForm = new Form1();

            NetConfiguration config = new NetConfiguration("OoBSample");
            config.MaxConnections = 0; // we accept only OoB data
            config.Port = 14242;
            s_server = new NetServer(config);
            s_server.SetMessageTypeEnabled(NetMessageType.OutOfBandData, true);
            s_server.Start();

            s_readBuffer = s_server.CreateBuffer();

            Application.Idle += new EventHandler(OnAppIdle);
            Application.Run(s_mainForm);

            s_server.Shutdown("Bye");
        }
开发者ID:JeffM2501,项目名称:HackSharp,代码行数:20,代码来源:Program.cs

示例3: Run

        protected virtual void Run()
        {
            // create server and start listening for connections
            server = new NetServer(netConfig);
            server.SetMessageTypeEnabled(NetMessageType.ConnectionApproval, true);
            server.Start();

            buffer = server.CreateBuffer();

            while (true)
            {
                CheckUpdates();
                Thread.Sleep(1);
            }
        }
开发者ID:JeffM2501,项目名称:HackSharp,代码行数:15,代码来源:Host.cs

示例4: Main

		static void Main(string[] args)
		{
			NetConfiguration config = new NetConfiguration("durable");
			config.MaxConnections = 128;
			config.Port = 14242;
			NetServer server = new NetServer(config);

			server.SetMessageTypeEnabled(NetMessageType.ConnectionApproval, true);
			server.SetMessageTypeEnabled(NetMessageType.DebugMessage, true);
			//server.SetMessageTypeEnabled(NetMessageType.VerboseDebugMessage, true);
			server.SetMessageTypeEnabled(NetMessageType.StatusChanged, true);

			server.SimulatedMinimumLatency = 0.05f;
			server.SimulatedLatencyVariance = 0.025f;
			server.SimulatedLoss = 0.03f;

			server.Start();

			FileStream fs = new FileStream("./serverlog.txt", FileMode.Create, FileAccess.Write, FileShare.Read);
			StreamWriter wrt = new StreamWriter(fs);
			Output(wrt, "Log started at " + DateTime.Now);
			wrt.Flush();

			NetBuffer buffer = server.CreateBuffer();

			int expected = 1;

			Console.WriteLine("Press any key to quit");
			while (!Console.KeyAvailable)
			{
				NetMessageType type;
				NetConnection sender;
				if (server.ReadMessage(buffer, out type, out sender))
				{
					switch (type)
					{
						case NetMessageType.StatusChanged:
							if (sender.RemoteHailData != null)
								Output(wrt, "New status: " + sender.Status + " (" + buffer.ReadString() + ") Remote hail is: " + Encoding.ASCII.GetString(sender.RemoteHailData));
							else
								Output(wrt, "New status: " + sender.Status + " (" + buffer.ReadString() + ") Remote hail hasn't arrived.");
							break;
						case NetMessageType.BadMessageReceived:
						case NetMessageType.ConnectionRejected:
						case NetMessageType.DebugMessage:
							//
							// All these types of messages all contain a single string in the buffer; display it
							//
							Output(wrt, buffer.ReadString());
							break;
						case NetMessageType.VerboseDebugMessage:
							wrt.WriteLine(buffer.ReadString()); // don't output to console
							break;
						case NetMessageType.ConnectionApproval:
							if (sender.RemoteHailData != null &&
								Encoding.ASCII.GetString(sender.RemoteHailData) == "Hail from client")
							{
								Output(wrt, "Hail ok!");
								sender.Approve(Encoding.ASCII.GetBytes("Hail from server"));
							}
							else
							{
								sender.Disapprove("Wrong hail!");
							}
							break;
						case NetMessageType.Data:
							string str = buffer.ReadString();

							// parse it
							int nr = Int32.Parse(str.Substring(9));

							if (nr != expected)
							{
								Output(wrt, "Warning! Expected " + expected + "; received " + nr + " str is ---" + str + "---");
							}
							else
							{
								expected++;
								Console.Title = "Server; received " + nr + " messages";
							}

							break;
						default:
							Output(wrt, "Unhandled: " + type + " " + buffer.ToString());
							break;
					}
				}
				Thread.Sleep(1);
			}

			// clean shutdown
			wrt.Close();
			server.Shutdown("Application exiting");
		}
开发者ID:zakvdm,项目名称:Frenetic,代码行数:94,代码来源:Program.cs

示例5: StartServer

        private static void StartServer()
        {
            // create a configuration for the server
            NetConfiguration config = new NetConfiguration("EES");
            config.MaxConnections = 128;
            config.Port = 14242;

            // create server and start listening for connections
            NetServer server = new NetServer(config);
            server.SetMessageTypeEnabled(NetMessageType.DebugMessage, false);
            server.SetMessageTypeEnabled(NetMessageType.ConnectionApproval, true);
            server.Start();

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

            // keep running until the user presses a key
            Console.WriteLine("Press ESC to quit server");
            bool keepRunning = true;
            while (keepRunning)
            {
                NetMessageType type;
                NetConnection sender;

                // check if any messages has been received
                while (server.ReadMessage(buffer, out type, out sender))
                {
                    switch (type)
                    {
                        case NetMessageType.DebugMessage:
                            netevent.fireDebugMessage(buffer.ReadString());
                            break;

                        case NetMessageType.ConnectionApproval:
                            netevent.fireClientApproval(server, buffer, sender);
                            break;

                        case NetMessageType.StatusChanged:
                            netevent.fireStatusChanged(server, buffer, sender);
                            break;

                        case NetMessageType.Data:
                            netevent.fireDataRecieved(server, buffer, sender);
                            break;
                    }
                }

                // User pressed ESC?
                while (Console.KeyAvailable)
                {
                    ConsoleKeyInfo info = Console.ReadKey();

                    if (info.Key == ConsoleKey.Escape)
                    {
                        keepRunning = false;
                    }
                    else if (info.Key == ConsoleKey.I)
                    {
                        //Create line
                        Console.WriteLine("");

                        //Get config
                        Config server_config = Config.Instance;

                        foreach (DictionaryEntry entry in server_config.Server.client_connections)
                        {
                            Console.WriteLine("Client: '" + entry.Value + "' from: " + entry.Key);
                        }
                    }
                }

                Thread.Sleep(1);
            }

            server.Shutdown("Server exiting");
        }
开发者ID:rcrowe,项目名称:ees_xplane,代码行数:76,代码来源:Program.cs

示例6: OpenIP

        void OpenIP()
        {
            int port = net_port.Integer;

            svConfig.MaxConnections = 64;
            svConfig.Port = port;
            server = new NetServer(svConfig);
            server.Configuration.AnswerDiscoveryRequests = false;
            server.EnabledMessageTypes |= NetMessageType.OutOfBandData;
            //server.SimulatedMinimumLatency = 0.7f;
            server.SetMessageTypeEnabled(NetMessageType.ConnectionApproval, true);
            try
            {
                server.Start();
            }
            catch (NetException ex)
            {
                // Try the next port
                server.Configuration.Port = ++port;
                server.Start();
            }
            client = new NetClient(clConfig);
            //client.SimulatedMinimumLatency = 0.2f;
            //client.RunSleep = 0;
            client.EnabledMessageTypes |= NetMessageType.OutOfBandData;
            client.Start();
        }
开发者ID:maesse,项目名称:CubeHags,代码行数:27,代码来源:Net.cs


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