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


C# NetServer.RegisterReceivedCallback方法代码示例

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


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

示例1: Initialize

        public static void Initialize()
        {
            NetServer = new NetServer(new NetPeerConfiguration("XnaMultiplayerGame")
                                      	{
                                      		Port = 5555
                                      	});

            NetServer.RegisterReceivedCallback(MessageReceived);

            NetServer.Start();

            Clients = new List<Client>();
        }
开发者ID:Skippeh,项目名称:Learning-Networking,代码行数:13,代码来源:Server.cs

示例2: start

        public static void start()
        {
            net = new NetServer(config);

            net.RegisterReceivedCallback(new SendOrPostCallback((e) =>
            {
                message = ((NetServer)e).ReadMessage();
                messageRecieved(message);
            }), new SynchronizationContext());

            print("info", "Starting...");
            net.Start();
            print("info", "Server running");
        }
开发者ID:law4x,项目名称:stonevox3d,代码行数:14,代码来源:Server.cs

示例3: Init

        public void Init(string app_identifier, int listen_port, int max_connections, int interval_ms, bool use_multi_thread)
        {
            this.app_identifier = app_identifier;
            this.interval_ms = interval_ms;

            NetPeerConfiguration config = new NetPeerConfiguration(this.app_identifier);
            config.MaximumConnections = max_connections;
            config.Port = listen_port;

            net_server = new NetServer(config);

            if (SynchronizationContext.Current == null)
            {
                SynchronizationContext.SetSynchronizationContext(new STASynchronizationContext());
            }

            if (use_multi_thread == false && SynchronizationContext.Current != null)
            {
                net_server.RegisterReceivedCallback(new SendOrPostCallback(GotMessage));
            }
            else
            {
                net_worker = new BackgroundWorker();
                net_worker.DoWork += new DoWorkEventHandler(net_worker_DoWork);
                net_worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(net_worker_RunWorkerCompleted);
            }

            tick_timer = new Timer(e =>
            {
                try
                {
                    if (OnTick != null && use_multi_thread && SynchronizationContext.Current != null)
                    {
                        SynchronizationContext.Current.Post(x =>
                        {
                            OnTick();
                        }, null);

                    }
                    else
                    {
                        OnTick();
                    }
                }
                catch (System.Exception ex)
                {
                    Console.WriteLine("Tick timer exception = {0}", ex.Message);
                }
            });
        }
开发者ID:jeidee,项目名称:Lidgren.Network.Wrapper,代码行数:50,代码来源:MessageServer.cs

示例4: ServerManager

        private ServerManager()
        {
            WorldHelper.SetMessagingProviders(_ClientToServer, _ServerToClient);

             SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

             NetPeerConfiguration peerConfig = ServerWorldManager.Instance.Configuration.Network.CreateNetPeerConfigurationUdp();
             peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.DebugMessage, true);
             peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.ErrorMessage, true);
             peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.VerboseDebugMessage, true);
             peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.WarningMessage, true);

             _Server = new NetServer(peerConfig);
             _Server.RegisterReceivedCallback(new SendOrPostCallback(ReceivedMessage));

             _WebServer = new WebHost(ServerWorldManager.Instance.Configuration.Network.Web);
        }
开发者ID:daxola123,项目名称:Qbes,代码行数:17,代码来源:ServerManager.cs

示例5: Server

 public Server()
 {
     // set up network
     NetPeerConfiguration config = new NetPeerConfiguration("gamajama");
     config.MaximumConnections = 100;
     config.UseMessageRecycling = true;
     config.Port = 14240;
     config.AcceptIncomingConnections = true;
     config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
     config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
     config.EnableMessageType(NetIncomingMessageType.StatusChanged);
     config.EnableMessageType(NetIncomingMessageType.ErrorMessage);
     config.EnableMessageType(NetIncomingMessageType.DebugMessage);
     config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage);
     config.EnableMessageType(NetIncomingMessageType.Data);
     s_server = new NetServer(config);
     s_server.RegisterReceivedCallback(new SendOrPostCallback(getData));
     s_server.Start();
 }
开发者ID:huynhrichy,项目名称:PandaPanic,代码行数:19,代码来源:Server.cs

示例6: Main

        public static void Main(string[] args)
        {
            Console.WriteLine("[SERVER] Testing Lidgren-Network-v3...");

            NetPeerConfiguration serverConfig = new NetPeerConfiguration("test");
            serverConfig.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
            serverConfig.EnableMessageType(NetIncomingMessageType.Data);
            serverConfig.MaximumConnections = 32;
            serverConfig.Port = 80;
            NetServer server = new NetServer(serverConfig);
            server.Start();
            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
            var thread = new SendOrPostCallback(GotMessage);
            server.RegisterReceivedCallback(thread);
            while (true)
            {
                Console.ReadLine();
                //    NetIncomingMessage inc;
                //    while ((inc = server.ReadMessage()) != null)
                //    {

                //        switch (inc.MessageType)
                //        {
                //            case NetIncomingMessageType.DiscoveryRequest:

                //                // Create a response and write some example data to it
                //                NetOutgoingMessage response = server.CreateMessage();
                //                response.Write(" Connected to: the person right next to you");

                //                // Send the response to the sender of the request
                //                server.SendDiscoveryResponse(response, inc.SenderEndPoint);
                //                break;
                //            case NetIncomingMessageType.Data:

                //                Console.WriteLine(inc.ReadString());
                //                break;
                //        }
                //    }

            }
        }
开发者ID:uwrov,项目名称:teaching,代码行数:41,代码来源:Program.cs

示例7: Main

        static void Main(string[] args)
        {
            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
            players = new List<Player>();
            Console.WriteLine("This is the Server");//This is the server
            Config = new NetPeerConfiguration("DND Server");//use app id to recognize
            Console.WriteLine("Server configuration created.");
            //server and clients per to make sure they are the same on the client and server
            Config.Port = _SERVERPORT;//Port
            ///enables connection approval message type.  In Lidgren all messages are split into message types
            ///so you can ignor some or all of them.
            Config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            Server = new NetServer(Config); //Intialize with the config
            Console.WriteLine("Server socket initialized.");
            Server.RegisterReceivedCallback(new SendOrPostCallback(RecieveData));
            //This will call the recieve data callback whenever the server recieves data
            //from a client in a separate thread
            Server.Start();//Start the server
            Console.WriteLine("Server Started");
            //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            //An example input manager to get respont on console
            new Thread(new ThreadStart(delegate
                {
                    Console.WriteLine("Checking for input");
                    string input;

                    while ((input = Console.ReadLine()) != null)
                    {
                        string[] prms = input.Split(' ');//params for the input

                        switch (prms[0])//The first param is the command name
                        {
                            default:
                                break;

                        }

                    }
                })).Start();
            //END INPUT MANAGEMENT
        }
开发者ID:TimBritton,项目名称:Server,代码行数:41,代码来源:Server.cs

示例8: Main

        public static void Main(string[] args)
        {
            Console.WriteLine("[SERVER] Testing Lidgren-Network-v3...");
            NetPeerConfiguration serverConfig = new NetPeerConfiguration("test");
            serverConfig.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
            serverConfig.MaximumConnections = 32;
            serverConfig.Port = 12345;
            NetServer server = new NetServer(serverConfig);
            server.Start();

            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
            server.RegisterReceivedCallback(new SendOrPostCallback(GotMessage));

            while(true) {
                string msg = Console.ReadLine();

                NetOutgoingMessage sendMsg = server.CreateMessage();
                sendMsg.Write("[SERVER] " + msg);

                server.SendToAll(sendMsg, NetDeliveryMethod.ReliableOrdered);
            }
        }
开发者ID:uwrov,项目名称:teaching,代码行数:22,代码来源:Server.cs

示例9: StartServer

        public void StartServer()
        {
            players = new List<PlayerObject>();
            server = new NetServer(config);
            server.RegisterReceivedCallback(new SendOrPostCallback(HandleMessages));
            server.Start();
            Console.WriteLine(" Crab Battle server open for business on Port: "+config.Port);
            Console.WriteLine(" ConnectionTimeout "+config.ConnectionTimeout+" PingInterval "+config.PingInterval);
            Console.WriteLine(" Max number of players is: "+config.MaximumConnections);

            t1 = new Thread(new ThreadStart(RunGameLoop));
            t1.Name = "Game Loop Thread";
            t1.Start();
            Thread.Sleep(500);
            // Replaced by RegisterReceivedCallback a.k.a HandleMessages
            /*
            t2 = new Thread(new ThreadStart(MessageProcessor));
            t2.Name = "Message Loop Thread";
            t2.Start();
            */
        }
开发者ID:tomoprime,项目名称:CrabBattle,代码行数:21,代码来源:GameServer.cs

示例10: Run

        public void Run()
        {
            bool running = true;

            Console.WriteLine("Backup Remote");
            Console.Write("Master key: ");

            string key = "";
            ConsoleKeyInfo info;

            do
            {
                info = Console.ReadKey(true);

                if (info.Key != ConsoleKey.Backspace && info.Key != ConsoleKey.Enter)
                {
                    key += info.KeyChar;
                    Console.Write("*");
                }
                else if (info.Key == ConsoleKey.Backspace && key.Length > 0)
                {
                    key = key.Substring(0, key.Length - 1);
                    Console.Write("\b \b");
                }
            }
            while (info.Key != ConsoleKey.Enter);

            keyHash = GetHash(key);
            key = string.Empty;

            Console.WriteLine();
            Console.Write("Backup directory: ");

            backupDir = Console.ReadLine();

            if (!Directory.Exists(backupDir))
            {
                Console.WriteLine("Directory doesn't exist");
                return;
            }

            Console.WriteLine("Initializing...");

            Command.Register("close", a => running = false);
            Command.Register("manifest", a =>
            {
                if (a.Length == 0)
                {
                    Console.WriteLine(targetManager.GetManifestJSON());
                    return;
                }

                if (a[0] == "save")
                {
                    Console.WriteLine("Forced manifest save");
                    targetManager.SaveManifest();
                }
            });

            targetManager = new TargetManager(backupDir);

            NetPeerConfiguration cfg = new NetPeerConfiguration("BackupUtil");
            cfg.Port = 6969;

            cfg.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            cfg.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);

            SynchronizationContext sync = new SynchronizationContext();
            SynchronizationContext.SetSynchronizationContext(sync);

            server = new NetServer(cfg);
            server.RegisterReceivedCallback(new SendOrPostCallback(MessageReceived), sync);
            server.Start();

            Console.WriteLine("Initialized");

            string line;
            while (running)
            {
                line = Console.ReadLine();

                string[] lineArgs = line.Split(' ');
                if (!Command.Run(lineArgs[0], lineArgs.Skip(1).ToArray()))
                    Console.WriteLine("Invalid command");
            }

            Console.WriteLine("Closing...");

            server.Shutdown("bye"); // TODO: figure out why client doesn't receive the message that the server is shut down
        }
开发者ID:Spanfile,项目名称:BackupUtil,代码行数:90,代码来源:Remote.cs

示例11: Server

 public Server()
 {
     NetPeerConfiguration cfg = new NetPeerConfiguration("bandit");
     cfg.Port = 5635;
     server = new NetServer(cfg);
     server.RegisterReceivedCallback(new SendOrPostCallback(GotLidgrenMessage), new SynchronizationContext());
     gameStarted = DateTime.Now;
     lootTimer = new Timer(o => PlaceLoot(), null, 0, LOOT_INTERVAL);
     timeTimer = new Timer(o => UpdateTime(), null, 0, TIME_INTERVAL);
     frameTimer = new Timer(o => EveryFrame(), null, 0, FRAME_INTERVAL);
 }
开发者ID:libjared,项目名称:iris,代码行数:11,代码来源:Server.cs

示例12: Main

        static void Main(string[] args)
        {
            Console.WriteLine("Akanonda Server");
            Console.WriteLine("---------------");

            // NetServer START
            NetPeerConfiguration netconfig = new NetPeerConfiguration("game");
            netconfig.MaximumConnections = settings.MaxConnections;
            netconfig.Port = settings.GamePort;
            netserver = new NetServer(netconfig);

            NetPeerConfiguration config = new NetPeerConfiguration("chat");
            config.MaximumConnections = 100;
            config.Port = settings.ChatPort;
            chatServer = new NetServer(config);

            SurvivalTimer = new System.Timers.Timer();
            SurvivalTimer.Interval = 1000;
            SurvivalTimer.Elapsed += new ElapsedEventHandler(gameSecondTick);
            SurvivalTimer.Start();

            if (SynchronizationContext.Current == null)
                SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

            netserver.RegisterReceivedCallback(new SendOrPostCallback(ReceiveData));

            netserver.Start();
            StartChat();

            game = Game.Instance;

            gameSpeedTimer = new System.Timers.Timer(settings.GameSpeed);
            gameSpeedTimer.Elapsed += new ElapsedEventHandler(gameSpeedTimer_Elapsed);
            gameSpeedTimer.Enabled = true;

            Console.Write("Command: ");
            while (true)
            {
                string input = Console.ReadLine();
                switch (input)
                {
                    case "start":
                        break;
                    case "status":
                        Console.WriteLine(netserver.ConnectionsCount);
                        break;
                    case "exit":
                        netserver.Shutdown("Exit");
                        Environment.Exit(0);
                        break;
                    case "stop Chat":
                        StopChat();
                        Console.WriteLine("Chat stopped");
                        break;
                    case "start Chat":
                        StartChat();
                        Console.WriteLine("Chat started");
                        break;
                    case "kick Player":
                        Console.WriteLine("Enter Player name:");
                        string playerToKick = Console.ReadLine();
                        Player playerToFind = game.PLayerList.Find(item => item.name == playerToKick);
                        if (playerToFind != null)
                        {
                            game.addDeadRemoveLivingPlayer(playerToFind.guid);
                        }
                        break;
                    default:
                        Console.WriteLine("Command not found.");
                        break;
                }
                Console.Write("Command: ");
            }
        }
开发者ID:JueZ,项目名称:ITP,代码行数:74,代码来源:Program.cs

示例13: Main

        static void Main(string[] args)
        {
            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
            Console.WriteLine("This is the server");
            Players = new List<Player>();
            Config = new NetPeerConfiguration("MyGame");
            Console.WriteLine("Server configuration created.");
            Config.Port = 7777;
            Config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            Server = new NetServer(Config);
            Console.WriteLine("Server socket initialized");
            Server.RegisterReceivedCallback(new SendOrPostCallback(ReceiveData));
            Server.Start();
            Console.WriteLine("Server started");

            new Thread(new ThreadStart(delegate
                {
                    string input;

                    while ((input = Console.ReadLine()) != null)
                    {
                        Console.WriteLine("New Input.");
                        string[] prms = input.Split(' ');

                        switch (prms[0])
                        {
                            //No commands on server as of now
                        }
                    }
                })).Start();
        }
开发者ID:ChosunOne,项目名称:Network_Test_1,代码行数:31,代码来源:Program.cs


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