本文整理汇总了C#中Lidgren.Network.NetPeerConfiguration类的典型用法代码示例。如果您正苦于以下问题:C# NetPeerConfiguration类的具体用法?C# NetPeerConfiguration怎么用?C# NetPeerConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NetPeerConfiguration类属于Lidgren.Network命名空间,在下文中一共展示了NetPeerConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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");
}
示例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();
}
示例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();
}
示例4: Client_Model2
public Client_Model2()
{
_netconfig = new NetPeerConfiguration("SkyNet");
_client = new NetClient(_netconfig);
_assembly = new SuperAssembly("Client");
_listen=new Thread(Listen);
}
示例5: Server_Model2
public Server_Model2()
{
_netconfig = new NetPeerConfiguration("SkyNet") { Port = 9000 };
_server = new NetServer(_netconfig);
_assembly = new SuperAssembly("Server");
_thread = new Thread(Thread);
}
示例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);
}
}
}
示例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;
}
示例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);
}
示例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");
}
示例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!");
}
示例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();
}
示例12: CozyClient
public CozyClient(string ClientName)
{
NetPeerConfiguration config = new NetPeerConfiguration(ClientName);
config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
InnerClient = new NetClient(config);
InnerClient.RegisterReceivedCallback(RecivePacket);
}
示例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();
};
}
示例14: Client
public Client()
{
NetPeerConfiguration config = new NetPeerConfiguration("CozyAnywhere");
config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
client = new NetClient(config);
client.RegisterReceivedCallback(RecivePacket);
}
示例15: NetworkClient
public NetworkClient(string Host, int Port)
{
Config = new NetPeerConfiguration("GameServer01");
ClientConnection = new NetClient(Config);
ClientConnection.Start();
ClientConnection.Connect(Host, Port);
}