• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Network.NetPeerConfiguration类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



NetPeerConfiguration类属于Lidgren.Network命名空间,在下文中一共展示了NetPeerConfiguration类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

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


示例2: WizardryGameServer

        /// <summary>
        /// Default constructor for the WizardryGameServer class.
        /// </summary>
        public WizardryGameServer()
        {
            graphics = new GraphicsDeviceManager( this );
            Content.RootDirectory = "Content";
            textureProvider = new TextureProvider( Content );

            // Windows Settings for the XNA window
            Window.Title = "Wizardry Server";
            graphics.PreferredBackBufferWidth = 200;
            graphics.PreferredBackBufferHeight = 1;

            // Set up the lobbies list
            lobbies = new GameLobby[GameSettings.MAX_LOBBIES];
            for ( int i = 0; i < GameSettings.MAX_LOBBIES; ++i )
            {
                lobbies[i] = null;
            }

            playerLobbies = new ConcurrentDictionary<long, int>();

            // Setup the server configuration
            NetPeerConfiguration config = new NetPeerConfiguration( GameSettings.APP_NAME );
            config.Port = GameSettings.SERVER_PORT_NUM;
            config.EnableMessageType( NetIncomingMessageType.DiscoveryRequest );

            // Start the server
            server = new NetServer( config );
            server.Start();
            WriteConsoleMessage( "Server starting!" );

            // Start the Packet Receiver thread
            Thread packets = new Thread( new ThreadStart( this.PacketProcessor ) );
            packets.Start();
        }
开发者ID:nezek6,项目名称:Wizardry,代码行数:37,代码来源:WizardryGameServer.cs


示例3: MasterServer

        /// <summary>
        ///     Server constructor, starts the server and connects to all region servers.
        /// </summary>
        /// <remarks>
        ///     TODO: Make the config file be able to be in a different location. Load from command line.
        /// </remarks>
        public MasterServer()
        {
            //Load this region server's junk from xml
            XmlSerializer deserializer = new XmlSerializer(typeof(MasterConfig));
            MasterConfig masterconfig = (MasterConfig)deserializer.Deserialize(XmlReader.Create(@"C:\Users\Addie\Programming\Mobius\Mobius.Server.MasterServer\bin\Release\MasterData.xml"));
            //Start it with the name MobiusMasterServer, and let connection approvals be enabled
            var config = new NetPeerConfiguration(masterconfig.ServerName);
            config.Port = masterconfig.ServerPort;
            config.MaximumConnections = masterconfig.MaxConnections;
            config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            LidgrenServer = new NetServer(config);

            RegionServers = new Dictionary<ushort, NetClient>();
            foreach(RegionInfo info in masterconfig.RegionServers)
            {
                NetClient region = new NetClient(new NetPeerConfiguration(info.ServerName));
                region.Start();
                region.Connect(info.ServerIp, info.ServerPort);
                RegionServers.Add(info.RegionId, region);
            }

            //Initialize our data structures
            Users = new Dictionary<Guid, User>();
            UserIdToCharacters = new Dictionary<Guid, List<Character>>();
            //Start the server
            LidgrenServer.Start();
        }
开发者ID:addiem7c5,项目名称:Old-Stability-Stuff,代码行数:33,代码来源:MasterServer.cs


示例4: Client_Model2

 public Client_Model2()
 {
     _netconfig = new NetPeerConfiguration("SkyNet");
     _client = new NetClient(_netconfig);
     _assembly = new SuperAssembly("Client");
     _listen=new Thread(Listen);
 }
开发者ID:hipolipolopigus,项目名称:SkyNet_Old,代码行数:7,代码来源:Client_Model2.cs


示例5: Server_Model2

 public Server_Model2()
 {
     _netconfig = new NetPeerConfiguration("SkyNet") { Port = 9000 };
     _server = new NetServer(_netconfig);
     _assembly = new SuperAssembly("Server");
     _thread = new Thread(Thread);
 }
开发者ID:hipolipolopigus,项目名称:SkyNet_Old,代码行数:7,代码来源:Server_Model2.cs


示例6: Main

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

            NetPeerConfiguration clientConfig = new NetPeerConfiguration("test");
            clientConfig.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
            NetClient client = new NetClient(clientConfig);
            client.Start();

            Console.WriteLine("IP to connect to: ");
            String ip = Console.ReadLine();
            client.Connect("192.168.1.2", 80);

            while (true)
            {
                if (client.ServerConnection != null)
                {
                    string msg = Console.ReadLine();

                    NetOutgoingMessage sendMsg = client.CreateMessage();
                    sendMsg.Write(msg);
                    client.SendMessage(sendMsg, NetDeliveryMethod.ReliableOrdered);
                }
            }
        }
开发者ID:uwrov,项目名称:teaching,代码行数:25,代码来源:Client.cs


示例7: GetStandardConfiguration

 public static NetPeerConfiguration GetStandardConfiguration(this NetPeerConfiguration self)
 {
     var config = new NetPeerConfiguration("NovaRat");
     // Disable all message types
     config.DisableMessageType(NetIncomingMessageType.ConnectionApproval);
     config.DisableMessageType(NetIncomingMessageType.ConnectionLatencyUpdated);
     config.DisableMessageType(NetIncomingMessageType.Data);
     config.DisableMessageType(NetIncomingMessageType.DebugMessage);
     config.DisableMessageType(NetIncomingMessageType.DiscoveryRequest);
     config.DisableMessageType(NetIncomingMessageType.DiscoveryResponse);
     config.DisableMessageType(NetIncomingMessageType.Error);
     config.DisableMessageType(NetIncomingMessageType.ErrorMessage);
     config.DisableMessageType(NetIncomingMessageType.NatIntroductionSuccess);
     config.DisableMessageType(NetIncomingMessageType.Receipt);
     config.DisableMessageType(NetIncomingMessageType.UnconnectedData);
     config.DisableMessageType(NetIncomingMessageType.VerboseDebugMessage);
     config.DisableMessageType(NetIncomingMessageType.WarningMessage);
     // Enable only what we need
     config.EnableMessageType(NetIncomingMessageType.UnconnectedData);
     config.EnableMessageType(NetIncomingMessageType.NatIntroductionSuccess);
     config.EnableMessageType(NetIncomingMessageType.StatusChanged);
     //config.EnableMessageType(NetIncomingMessageType.DebugMessage);
     //config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage);
     //config.EnableMessageType(NetIncomingMessageType.WarningMessage);
     //config.EnableMessageType(NetIncomingMessageType.ErrorMessage);
     config.AcceptIncomingConnections = true;
     // No need to assign a port, as the OS will automatically assign an available port
     return config;
 }
开发者ID:theslyone,项目名称:RemoteDesktop,代码行数:29,代码来源:NetPeerConfigurationExtensions.cs


示例8: Main

        static void Main()
        {
            //would block send buffer full
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            MainForm = new Form1();

            NetPeerConfiguration config = new NetPeerConfiguration("many");

            config.Port = 14242;
            config.AutoFlushSendQueue = true;
            config.SendBufferSize = 1024 * 512;
            #if DEBUG
            config.SimulatedLoss = 0.02f;
            #else
            // throw new Exception("Sample not relevant in RELEASE; statistics needed to make sense!");
            #endif
            config.MaximumConnections = 50000;

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

            var swin = new NetPeerSettingsWindow("Server settings", Program.Server);
            swin.Show();

            Application.Idle += new EventHandler(AppLoop);
            Application.Run(MainForm);
        }
开发者ID:RainsSoft,项目名称:lidgren-network-gen3,代码行数:28,代码来源:Program.cs


示例9: TrackingServer

 public TrackingServer(int port, string applicationName)
 {
   NetPeerConfiguration config = new NetPeerConfiguration(applicationName);
   config.Port = port;
   netServer = new NetServer(config);
   Console.WriteLine("Server " + applicationName + " started succesfully");
 }
开发者ID:vs-team,项目名称:casanova-mk2,代码行数:7,代码来源:TrackingServer.cs


示例10: GameServer

        public GameServer()
        {
            /* Load Resources */
            Console.WriteLine("Loading Resources...");
            Resources = new ResourceManager();
            Resources.Load();

            /* Setting Up Server */
            Console.WriteLine("Starting Up Server...");
            //Package.RecompilePackages();
            //CodeManager StartUp = Package.GetPackage(Game.ServerInfo.StartupPackage).CodeManager;
            //StartUp.RunMain();
            //Game.World.Chunks.ClearWorldGen();
            //Game.World.Chunks.AddWorldGens(StartUp.GetWorldGens());
            Game.World.ClearWorldGen();
            List<WorldGenerator> temp = new List<WorldGenerator>();
            temp.Add(new WorldGenerator());
            Game.World.AddWorldGen(temp);

            /* Listen for Clients */
            NetPeerConfiguration Configuration = new NetPeerConfiguration("FantasyScape");
            Configuration.Port = 54987;
            Configuration.MaximumConnections = 20;
            Server = new NetServer(Configuration);
            Server.Start();
            Message.RegisterServer(Server);

            UpdateTimer = new Stopwatch();
            UpdateTimer.Start();

            Console.WriteLine("Ready!");
        }
开发者ID:CloneDeath,项目名称:FantasyScape,代码行数:32,代码来源:GameServer.cs


示例11: SetupServer

        public void SetupServer(string gameName, int port = 14242, int maxConnections = 20)
        {
            // Create new instance of configs. Parameter is "application Id". It has to be same on client and server.
            var config = new NetPeerConfiguration(gameName) { Port = port, MaximumConnections = maxConnections };
            _heroList = new List<LoginInfo>();
            // Set server port

            // Max client amount
            // Enable New messagetype. Explained later
            config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);

            // Create new server based on the configs just defined
            _gameServer = new NetServer(config);

            // Start it
            _gameServer.Start();

            // Eh..
            Console.WriteLine("Server Started");

            // Object that can be used to store and read messages
            NetIncomingMessage inc;
            _serverThread = new Thread(() =>
            {
                while (true)
                {
                    ServerLoop();
                }
            });
            _serverThread.IsBackground = true;
            _serverThread.Start();
        }
开发者ID:Choochoo,项目名称:Ship,代码行数:32,代码来源:Host.cs


示例12: CozyClient

 public CozyClient(string ClientName)
 {
     NetPeerConfiguration config = new NetPeerConfiguration(ClientName);
     config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
     InnerClient = new NetClient(config);
     InnerClient.RegisterReceivedCallback(RecivePacket);
 }
开发者ID:xxy1991,项目名称:cozy,代码行数:7,代码来源:CozyClient.Main.cs


示例13: Initialize

        public void Initialize()
        {
            TextBox IP = new TextBox(MainCanvas.Instance);
            IP.Text = "127.0.0.1";
            IP.SetPosition(10, 10);

            NumericUpDown Port = new NumericUpDown(MainCanvas.Instance);
            Port.Max = ushort.MaxValue;
            Port.Min = 0;
            Port.Value = 54987;
            Port.SetPosition(10, 40);

            Button Connect = new Button(MainCanvas.Instance);
            Connect.Text = "Connect";
            Connect.SetPosition(10, 70);
            Connect.Clicked += delegate(Base sender, ClickedEventArgs args) {
                NetPeerConfiguration config = new NetPeerConfiguration("Xanatos");
                Program.Connection = new NetClient(config);
                Program.Connection.Start();
                Program.Connection.Connect(IP.Text, (int)Port.Value);

                while (((NetClient)Program.Connection).ConnectionStatus != NetConnectionStatus.Connected) {
                    Thread.Sleep(500);
                    Program.Connection.ReadMessages(new List<NetIncomingMessage>());
                }
                Message.RegisterClient(Program.Connection);

                new PlayerJoining().Send();
            };
        }
开发者ID:CloneDeath,项目名称:Xanatos,代码行数:30,代码来源:Connect.cs


示例14: Client

 public Client()
 {
     NetPeerConfiguration config = new NetPeerConfiguration("CozyAnywhere");
     config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
     client                      = new NetClient(config);
     client.RegisterReceivedCallback(RecivePacket);
 }
开发者ID:shangshen,项目名称:cozy,代码行数:7,代码来源:ClientMain.cs


示例15: NetworkClient

 public NetworkClient(string Host, int Port)
 {
     Config = new NetPeerConfiguration("GameServer01");
     ClientConnection = new NetClient(Config);
     ClientConnection.Start();
     ClientConnection.Connect(Host, Port);
 }
开发者ID:fusspawn,项目名称:sobriety,代码行数:7,代码来源:NetworkClient.cs


示例16: NetworkServer

 /// <summary>
 /// Initializes a new instance of the <see cref="NetworkServer" /> class.
 /// </summary>
 /// <param name="applicationIdentifier">The application identifier.</param>
 /// <param name="port">The port.</param>
 public NetworkServer(string applicationIdentifier, int port)
 {
     var config = new NetPeerConfiguration(applicationIdentifier);
     config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
     config.Port = port;
     this.server = new NetServer(config);
 }
开发者ID:WaveEngine,项目名称:Extensions,代码行数:12,代码来源:NetworkServer.cs


示例17: Connect

        public static void Connect(IPEndPoint endpoint, MMDevice device, ICodec codec)
        {
            var config = new NetPeerConfiguration("airgap");

            _client = new NetClient(config);
            _client.RegisterReceivedCallback(MessageReceived);

            _client.Start();

            _waveIn = new WasapiLoopbackCapture(device);
            _codec = codec;

            _sourceFormat = _waveIn.WaveFormat;
            _targetFormat = new WaveFormat(_codec.SampleRate, _codec.Channels); // format to convert to

            _waveIn.DataAvailable += SendData;
            _waveIn.RecordingStopped += (sender, args) => Console.WriteLine("Stopped");
            // TODO: RecordingStopped is called when you change the audio device settings, should recover from that

            NetOutgoingMessage formatMsg = _client.CreateMessage();
            formatMsg.Write(_targetFormat.Channels);
            formatMsg.Write(_targetFormat.SampleRate);
            formatMsg.Write(codec.Name);

            _client.Connect(endpoint, formatMsg);
        }
开发者ID:JamieH,项目名称:AudioGap,代码行数:26,代码来源:Network.cs


示例18: NetworkImp

        /// <summary>
        /// Initializes a new instance of the <see cref="NetworkImp"/> class.
        /// </summary>
        public NetworkImp()
        {
            _netConfig = new NetPeerConfiguration("FUSEE3D");

            IncomingMsg = new List<INetworkMsg>();

            _config = new NetConfigValues
                          {
                              SysType = SysType.None,
                              DefaultPort = 14242,
                              Discovery = false,
                              ConnectOnDiscovery = false,
                              DiscoveryTimeout = 5000,
                              RedirectPackets = false,
                          };

            // _netConfig.RedirectedPacketsList.CollectionChanged += PackageCapture;
            Connections = new List<INetworkConnection>();

            Status = new NetStatusValues
            {
                Connected = false,
                LastStatus = ConnectionStatus.None
            };
        }
开发者ID:GameProduction,项目名称:ScharfschiessenGame,代码行数:28,代码来源:NetworkImp.cs


示例19: ServerHandleConnections

        /// <summary>
        ///     Метод для работып отока обработчика входящих новых соединений с сервером
        /// </summary>
        private static void ServerHandleConnections(object obj) {
            Log.Print("Starting Listen connections", LogType.Network);

            var config = new NetPeerConfiguration(Settings.GameIdentifier) {
                Port = Settings.Port,
                MaximumConnections = Settings.MaxConnections,
                SendBufferSize = 400000,
                UseMessageRecycling = true,
            };

            /* Получаем возможные адреса сервера */
            Log.Print("Server IP's:", LogType.Network);
            Log.Print("-------", LogType.Network);
            IPAddress[] ipList = Dns.GetHostAddresses(Dns.GetHostName());
            foreach (IPAddress ip in ipList) {
                if (ip.AddressFamily == AddressFamily.InterNetwork) {
                    Log.Print(ip.ToString(), LogType.Network);
                }
            }
            Log.Print("-------", LogType.Network);

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

            // Запускаем обработчик пакетов
            StartProcessIncomingMessages();
        }
开发者ID:Insality,项目名称:essence-of-shadows,代码行数:30,代码来源:Server.cs


示例20: WorldClientBase

        public WorldClientBase(string protocolVersion)
        {
            this.protocolVersion = protocolVersion;

            // Net configuration
            NetPeerConfiguration cfg = new NetPeerConfiguration("Asteria");
            cfg.MaximumConnections = 1;
            cfg.ReceiveBufferSize = 4095;
            cfg.MaximumTransmissionUnit = 4095;
            #if DEBUG
            try
            {
                cfg.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage);
            }
            catch
            {
                Logger.Output(this, "Running in debug mode but using release Lidgren library version, Lidgren debug messages disabled!");
            }
            #endif
            client = new NetClient(cfg);
            client.Start();

            // Create objects needed.
            sendingQ = new Queue<ClientToServerMessage>(64);
            receivingQ = new Queue<NetIncomingMessage>(128);
            newDataArrivedEvent = new AutoResetEvent(false);

            messages = new Dictionary<MessageType, List<ServerToClientMessage>>();
            serializer = new ClientToServerMessageSerializer();
            deserializer = new ServerToClientMessageSerializer();

            isRunning = true;
        }
开发者ID:KtBkkr,项目名称:Asteria,代码行数:33,代码来源:WorldClientBase.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Network.NetServer类代码示例发布时间:2022-05-26
下一篇:
C# Network.NetPeer类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap