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


C# NetPeerConfiguration.SetMessageTypeEnabled方法代码示例

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


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

示例1: ClientConnection

        internal ClientConnection(bool dummy)
        {
            if (!dummy)
             {
            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

            NetPeerConfiguration peerConfig = new NetPeerConfiguration("Qbes");
            peerConfig.AutoFlushSendQueue = true;
            peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.DebugMessage, true);
            peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.ErrorMessage, true);
            peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.VerboseDebugMessage, true);
            peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.WarningMessage, true);
            _Client = new NetClient(peerConfig);
            _Client.RegisterReceivedCallback(new SendOrPostCallback(ReceivedMessage));
             }
        }
开发者ID:daxola123,项目名称:Qbes,代码行数:16,代码来源:ClientConnection.cs

示例2: Program

        public Program()
        {
            NetPeerConfiguration config = new NetPeerConfiguration("masterserver");
            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
            config.Port = API.MasterServer.MasterServerPort;

            peer = new NetPeer(config);
            peer.Start();
        }
开发者ID:imGoose,项目名称:SkyrimOnline,代码行数:9,代码来源:Program.cs

示例3: S_NetworkManager

        static S_NetworkManager()
        {
            NetPeerConfiguration lidServerConfig = new NetPeerConfiguration("chat");
            lidServerConfig.Port = 2323;
            lidServerConfig.PingInterval = HEARTBEAT_S;
            lidServerConfig.ConnectionTimeout = TIMEOUT_S;
            lidServerConfig.SetMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval, true);

            myLidServer = new NetServer(lidServerConfig);
            myLidServer.Start();
        }
开发者ID:nelak2,项目名称:Demiurge,代码行数:11,代码来源:S_NetworkManager.cs

示例4: Main

		static void Main(string[] args)
		{
			IPEndPoint masterServerEndpoint = NetUtility.Resolve("localhost", CommonConstants.MasterServerPort);

			NetPeerConfiguration config = new NetPeerConfiguration("game");
			config.SetMessageTypeEnabled(NetIncomingMessageType.NatIntroductionSuccess, true);
			config.Port = 14242;

			NetServer server = new NetServer(config);
			server.Start();

			Console.WriteLine("Server started; waiting 5 seconds...");
			System.Threading.Thread.Sleep(5000);

			var lastRegistered = -60.0f;

			while(Console.KeyAvailable == false || Console.ReadKey().Key != ConsoleKey.Escape)
			{
				// (re-)register periodically with master server
				if (NetTime.Now > lastRegistered + 60)
				{
					// register with master server
					NetOutgoingMessage regMsg = server.CreateMessage();
					regMsg.Write((byte)MasterServerMessageType.RegisterHost);
					IPAddress mask;
					IPAddress adr = NetUtility.GetMyAddress(out mask);
					regMsg.Write(server.UniqueIdentifier);
					regMsg.Write(new IPEndPoint(adr, 14242));
					Console.WriteLine("Sending registration to master server");
					server.SendUnconnectedMessage(regMsg, masterServerEndpoint);
					lastRegistered = (float)NetTime.Now;
				}

				NetIncomingMessage inc;
				while ((inc = server.ReadMessage()) != null)
				{
					switch (inc.MessageType)
					{
						case NetIncomingMessageType.VerboseDebugMessage:
						case NetIncomingMessageType.DebugMessage:
						case NetIncomingMessageType.WarningMessage:
						case NetIncomingMessageType.ErrorMessage:
							Console.WriteLine(inc.ReadString());
							break;
					}
				}

				System.Threading.Thread.Sleep(1);
			}

			Console.ReadKey();
		}
开发者ID:g1111111g,项目名称:lidgren-network-gen3,代码行数:52,代码来源:Program.cs

示例5: Run

        public static void Run(NetPeer peer)
        {
            NetPeerConfiguration config = new NetPeerConfiguration("Test");

            config.EnableMessageType(NetIncomingMessageType.UnconnectedData);
            if (config.IsMessageTypeEnabled(NetIncomingMessageType.UnconnectedData) == false)
                throw new NetException("setting enabled message types failed");

            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, false);
            if (config.IsMessageTypeEnabled(NetIncomingMessageType.UnconnectedData) == true)
                throw new NetException("setting enabled message types failed");

            Console.WriteLine("Misc tests OK");

            Console.WriteLine("Hex test: " + NetUtility.ToHexString(new byte[]{0xDE,0xAD,0xBE,0xEF}));
        }
开发者ID:JamieH,项目名称:lidgren-network-gen3,代码行数:16,代码来源:MiscTests.cs

示例6: ConnectionManager

        static ConnectionManager()
        {
            config = new NetPeerConfiguration("CWRUShare");
            config.AutoFlushSendQueue = true;
            config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
            config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
            config.EnableMessageType(NetIncomingMessageType.Data);
            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
            currentListView = new FileList();
            isListUpdated = false;

            config.Port = 14242;
            isConnected = false;

            server = new NetServer(config);
            server.Start();
        }
开发者ID:rdl40,项目名称:CWRUShare,代码行数:17,代码来源:ConnectionManager.cs

示例7: send

    public void send()
    {
        Patient PAT = new Patient(name.text, family.text, suffix.text, Convert.ToInt32(gender.text), Convert.ToDateTime(birthDate.text), polis.text, Convert.ToInt32(SocialStatus.text), Convert.ToInt32(Privileges.text));
        string json = JsonConvert.SerializeObject(PAT);

        int ClientPort = 25000;
        string ClientIP = "95.31.16.180";

        NetPeerConfiguration config = new NetPeerConfiguration(" ");
        config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
        config.Port = 1212;
        NetClient client = new NetClient(config);
        NetOutgoingMessage msg = client.CreateMessage();
        msg.Write((byte)0);
        msg.Write(json);
        client.Start();
        client.SendUnconnectedMessage(msg, ClientIP, ClientPort);

        Debug.Log("ОК");
    }
开发者ID:Cybermar95,项目名称:SummerProj,代码行数:20,代码来源:ser.cs

示例8: Start

    void Start()
    {
        try
        {
            Debug.Log("client try Start");
            config = new NetPeerConfiguration(" ");
            DontDestroyOnLoad(this);

            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
            config.Port = 1212;

            client = new NetClient(config);

            client.Start();
            Debug.Log("client Start");
        }
        catch (Exception e )
        {
            Debug.Log (e.Message);
        }
    }
开发者ID:Cybermar95,项目名称:SummerProj,代码行数:21,代码来源:Connector.cs

示例9: Main

        static void Main(string[] args)
        {
            Console.WriteLine("Server Started");
            
            Dictionary<IPEndPoint, AvailableGame> registeredHosts = new Dictionary<IPEndPoint, AvailableGame>();

            NetPeerConfiguration config = new NetPeerConfiguration("masterserver");
            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
            config.Port = 6000;

            NetPeer peer = new NetPeer(config);
            peer.Start();

            // keep going until ESCAPE is pressed
            Console.WriteLine("Press ESC to quit");
            while (!Console.KeyAvailable || Console.ReadKey().Key != ConsoleKey.Escape)
            {
                System.Threading.Thread.Sleep(10);
                NetIncomingMessage msg;
                while ((msg = peer.ReadMessage()) != null)
                {
                    switch (msg.MessageType)
                    {
                        case NetIncomingMessageType.UnconnectedData:
                            //
                            // We've received a message from a client or a host
                            //

                            // by design, the first byte always indicates action
                            switch (msg.ReadByte())
                            {
                                case 0: // register a new game
                                    // currently only one game per host per router.
                                    if (!registeredHosts.ContainsKey(msg.SenderEndpoint))
                                    {
                                        AvailableGame game = new AvailableGame();
                                        game.Count = msg.ReadInt32();
                                        game.GamerTag = msg.ReadString();
                                        game.PrivateGamerSlots = msg.ReadInt32();
                                        game.MaxGamers = msg.ReadInt32();
                                        game.IsHost = msg.ReadBoolean();
                                        game.InternalIP = msg.ReadIPEndpoint();
                                        game.ExternalIP = msg.SenderEndpoint;
                                        game.Game = msg.ReadString();


                                        Console.WriteLine("Got registration for host " + game.ToString());
                                        registeredHosts.Add(game.ExternalIP, game);
                                    }
                                    break;

                                case 1:
                                    // It's a client wanting a list of registered hosts
                                    Console.WriteLine("Sending list of " + registeredHosts.Count + " hosts to client " + msg.SenderEndpoint);
                                    string appid = msg.ReadString();
                                    foreach (AvailableGame g1 in registeredHosts.Values)
                                    {
                                        if (g1.Game == appid)
                                        {
                                            // send registered host to client
                                            NetOutgoingMessage om = peer.CreateMessage();
                                            om.Write(g1.Count);
                                            om.Write(g1.GamerTag);
                                            om.Write(g1.PrivateGamerSlots);
                                            om.Write(g1.MaxGamers);
                                            om.Write(g1.IsHost);
                                            om.Write(g1.InternalIP);
                                            om.Write(g1.ExternalIP);
                                            peer.SendUnconnectedMessage(om, msg.SenderEndpoint);
                                        }
                                    }

                                    break;
                                case 2:
                                    // It's a client wanting to connect to a specific (external) host
                                    IPEndPoint clientInternal = msg.ReadIPEndpoint();
                                    IPEndPoint hostExternal = msg.ReadIPEndpoint();
                                    string token = msg.ReadString();

                                    Console.WriteLine(msg.SenderEndpoint + " requesting introduction to " + hostExternal + " (token " + token + ")");

                                    // find in list
                                    foreach (AvailableGame elist in registeredHosts.Values)
                                    {
                                        if (elist.ExternalIP.Equals(hostExternal))
                                        {
                                            // found in list - introduce client and host to eachother
                                            Console.WriteLine("Sending introduction...");
                                            peer.Introduce(
                                                    elist.InternalIP, // host internal
                                                    elist.ExternalIP, // host external
                                                    clientInternal, // client internal
                                                    msg.SenderEndpoint, // client external
                                                    token // request token
                                            );
                                            break;
                                        }
                                    }
                                    break;
                                case 3:
//.........这里部分代码省略.........
开发者ID:Nailz,项目名称:MonoGame-Samples,代码行数:101,代码来源:Program.cs

示例10: Main

        static void Main(string[] args)
        {
            IPEndPoint masterServerEndpoint = NetUtility.Resolve("localhost", CommonConstants.MasterServerPort);

            NetPeerConfiguration config = new NetPeerConfiguration("game");
            config.SetMessageTypeEnabled(NetIncomingMessageType.NatIntroductionSuccess, true);
            config.Port = 14242;

            NetServer server = new NetServer(config);
            server.Start();

            Console.WriteLine("Server started; waiting 5 seconds...");
            System.Threading.Thread.Sleep(5000);

            var lastRegistered = -60.0f;

            while(Console.KeyAvailable == false || Console.ReadKey().Key != ConsoleKey.Escape)
            {
                // (re-)register periodically with master server
                if (NetTime.Now > lastRegistered + 60)
                {
                    // register with master server
                    NetOutgoingMessage regMsg = server.CreateMessage();
                    regMsg.Write((byte)MasterServerMessageType.RegisterHost);
                    IPAddress mask;
                    IPAddress adr = NetUtility.GetMyAddress(out mask);
                    regMsg.Write(server.UniqueIdentifier);
                    regMsg.Write(new IPEndPoint(adr, 14242));
                    Console.WriteLine("Sending registration to master server");
                    server.SendUnconnectedMessage(regMsg, masterServerEndpoint);
                    lastRegistered = (float)NetTime.Now;
                }

                NetIncomingMessage inc;
                while ((inc = server.ReadMessage()) != null)
                {
                    switch (inc.MessageType)
                    {
                        case NetIncomingMessageType.VerboseDebugMessage:
                        case NetIncomingMessageType.DebugMessage:
                        case NetIncomingMessageType.WarningMessage:
                        case NetIncomingMessageType.ErrorMessage:
                            Console.WriteLine(inc.ReadString());
                            break;
                        case NetIncomingMessageType.Data:
                            // incoming chat message from a client
                            string chat = inc.ReadString();
                            Console.WriteLine(chat);
                            //Output("Broadcasting '" + chat + "'");

                            // broadcast this to all connections, except sender
                            List<NetConnection> all = server.Connections; // get copy
                            all.Remove(inc.SenderConnection);

                            if (all.Count > 0) {
                                NetOutgoingMessage om = server.CreateMessage();
                                om.Write(NetUtility.ToHexString(inc.SenderConnection.RemoteUniqueIdentifier) + " said: " + chat);
                                server.SendMessage(om, all, NetDeliveryMethod.ReliableOrdered, 0);
                            }
                            break;
                    }
                }

                System.Threading.Thread.Sleep(1);
            }

            Console.ReadKey();
        }
开发者ID:RainsSoft,项目名称:lidgren-network-gen3,代码行数:68,代码来源:Program.cs

示例11: InitializeServer

        /// <summary>
        /// Set up the server, bind to a socket. Use Start to fully start the server after running this
        /// </summary>
        /// <param name="configuration"></param>
        public static void InitializeServer(ServerConfiguration configuration)
        {
            Configuration = configuration;

            if (peer != null && peer.Status != NetPeerStatus.NotRunning)
            {
                Debug.LogError("cannot start server while already running");
                return;
            }

            _netPeerConfiguration = new NetPeerConfiguration(Configuration.AppIdentifier);
            _netPeerConfiguration.Port = Configuration.ListenPort;
            _netPeerConfiguration.MaximumConnections = Configuration.MaximumConnections;
            connections = new IntDictionary<NetConnection>(Configuration.MaximumConnections);

            _netPeerConfiguration.SetMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval, true);

            peer = new NetServer(_netPeerConfiguration);

            peer.Start();

            var serverId = connections.Add(null);
            var serverPlayer = new Player();
            serverPlayer.Id = (ushort)serverId;
            Player.Server = serverPlayer;

            GameState.update += Update;
        }
开发者ID:Antaresgames,项目名称:PNet,代码行数:32,代码来源:PNetServer.cs

示例12: ClientServerStart

        static void ClientServerStart()
        {
            NetPeerConfiguration config = new NetPeerConfiguration(" ");
            config.Port = ClientPort;
            config.LocalAddress = IPAddress.Parse(ClientIP);
            config.MaximumConnections = 10000;
            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);

            MediatorServer = new NetServer(config);
            MediatorServer.Start();
        }
开发者ID:Cybermar95,项目名称:SummerProj,代码行数:11,代码来源:MediatorMain.cs

示例13: Main

        static void Main(string[] args)
        {
            Dictionary<long, ServerData> registeredHosts = new Dictionary<long, ServerData>();

            NetPeerConfiguration config = new NetPeerConfiguration("masterserver");
            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
            config.Port = SharedConfiguration.MasterServerEndPoint.Port;

            NetPeer peer = new NetPeer(config);
            peer.Start();

            // keep going until ESCAPE is pressed
            Console.WriteLine("Press ESC to quit");
            while (!Console.KeyAvailable || Console.ReadKey().Key != ConsoleKey.Escape) {
                NetIncomingMessage msg;
                while ((msg = peer.ReadMessage()) != null) {
                    switch (msg.MessageType) {
                        case NetIncomingMessageType.UnconnectedData:
                            //
                            // We've received a message from a client or a host
                            //

                            // by design, the first byte always indicates action
                            switch ((MasterServerMessageType)msg.ReadByte()) {
                                case MasterServerMessageType.RegisterHost:

                                    // It's a host wanting to register its presence
                                    var id = msg.ReadInt64(); // server unique identifier
                                    Console.WriteLine("Got registration for host " + id);

                                    ServerData serverData = new ServerData();
                                    serverData.IPEndPoint[0] = msg.ReadIPEndPoint();
                                    serverData.IPEndPoint[1] = msg.SenderEndPoint;

                                    serverData.ServerName = msg.ReadString();
                                    serverData.ScriptName = msg.ReadString();
                                    serverData.Players = msg.ReadInt32();
                                    serverData.MaxPlayers = msg.ReadInt32();

                                    registeredHosts[id] = serverData;
                                    break;

                                case MasterServerMessageType.RequestHostList:
                                    // It's a client wanting a list of registered hosts
                                    Console.WriteLine("Sending list of " + registeredHosts.Count + " hosts to client " + msg.SenderEndPoint);
                                    foreach (var kvp in registeredHosts) {
                                        // send registered host to client
                                        NetOutgoingMessage om = peer.CreateMessage();
                                        om.Write(kvp.Key);
                                        om.Write(kvp.Value.IPEndPoint[0]);
                                        om.Write(kvp.Value.IPEndPoint[1]);
                                        om.Write(kvp.Value.ServerName);
                                        om.Write(kvp.Value.ScriptName);
                                        om.Write(kvp.Value.Players);
                                        om.Write(kvp.Value.MaxPlayers);
                                        peer.SendUnconnectedMessage(om, msg.SenderEndPoint);
                                    }

                                    break;
                            }
                            break;

                        case NetIncomingMessageType.DebugMessage:
                        case NetIncomingMessageType.VerboseDebugMessage:
                        case NetIncomingMessageType.WarningMessage:
                        case NetIncomingMessageType.ErrorMessage:
                            // print diagnostics message
                            Console.WriteLine(msg.ReadString());
                            break;
                    }
                }
            }

            peer.Shutdown("shutting down");
        }
开发者ID:westre,项目名称:Stroopwaffle,代码行数:75,代码来源:Program.cs

示例14: Start

        public override void Start()
        {
            this.backgroundSprite = "MenuPanel";
            this.color = new Color32(50, 50, 50, 255);
            this.width = 350;
            this.height = 185;
            this.isVisible = false;
            this.position += new Vector3(-this.width/2, this.height/2 + 50);

            UILabel ipLabel = this.AddUIComponent<UILabel>();
            ipLabel.text = "IP:";
            ipLabel.pivot = UIPivotPoint.BottomRight;
            ipLabel.relativePosition = new Vector2(10, 10);

            m_ipTextField = CreateTextField();
            m_ipTextField.width = 140;
            m_ipTextField.text = "127.0.0.1";
            m_ipTextField.pivot = UIPivotPoint.BottomRight;
            m_ipTextField.relativePosition = new Vector2(55, 10);

            UILabel portLabel = this.AddUIComponent<UILabel>();
            portLabel.text = "Port:";
            portLabel.pivot = UIPivotPoint.BottomRight;
            portLabel.relativePosition = new Vector2(10, 45);

            m_portTextField = CreateTextField();
            m_portTextField.numericalOnly = true;
            m_portTextField.text = "27015";
            m_portTextField.pivot = UIPivotPoint.BottomRight;
            m_portTextField.relativePosition = new Vector2(55, 45);

            UIButton connectButton = CreateButton();
            connectButton.text = "CONNECT";
            connectButton.width = 100;
            connectButton.height = 60;
            connectButton.pivot = UIPivotPoint.BottomRight;
            connectButton.relativePosition = new Vector2(this.width - connectButton.width - 110, this.height - connectButton.height - 5);
            connectButton.eventClick += OnClickConnect;

            UIButton closeButton = CreateButton();
            closeButton.text = "CANCEL";
            closeButton.width = 100;
            closeButton.height = 60;
            closeButton.pivot = UIPivotPoint.BottomRight;
            closeButton.relativePosition = new Vector2(this.width - closeButton.width - 5, this.height - closeButton.height - 5);
            closeButton.eventClick += OnClickCancel;

            m_connectionInfoLabel = this.AddUIComponent<UILabel>();
            m_connectionInfoLabel.text = "";
            m_connectionInfoLabel.pivot = UIPivotPoint.TopLeft;
            m_connectionInfoLabel.relativePosition = new Vector2(10, 80);
            m_connectionInfoLabel.textAlignment = UIHorizontalAlignment.Left;

            NetPeerConfiguration config = new NetPeerConfiguration("FPSMod");
            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);

            m_netClient = new NetClient(config);
            m_netClient.Start();
        }
开发者ID:Fr0sZ,项目名称:Skylines-Multiplayer,代码行数:59,代码来源:JoinByIpPanel.cs

示例15: S_LidgrenContainer

        /// <summary>
        /// Initialize the Lidgren NetServer.
        /// </summary>
        public S_LidgrenContainer(ServerWindow setServerWindow)  //Need to know an instance of ChatWindow so we can pass commands along to it in HandleCustomMessages.
        {
            NetPeerConfiguration lidServerConfig = new NetPeerConfiguration("chat");
            lidServerConfig.Port = 2323;
            lidServerConfig.PingInterval = HEARTBEAT_S;
            lidServerConfig.ConnectionTimeout = TIMEOUT_S;
            lidServerConfig.SetMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval, true);

            myLidServer = new NetServer(lidServerConfig);
            myLidServer.Start();
        }
开发者ID:refactoryourmind,项目名称:yapper,代码行数:14,代码来源:S_LidgrenContainer.cs


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