本文整理汇总了C#中Lidgren.Network.NetServer.Start方法的典型用法代码示例。如果您正苦于以下问题:C# NetServer.Start方法的具体用法?C# NetServer.Start怎么用?C# NetServer.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetServer
的用法示例。
在下文中一共展示了NetServer.Start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: Main
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
MainForm = new Form1();
NetPeerConfiguration config = new NetPeerConfiguration("durable");
config.Port = 14242;
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
config.EnableUPnP = true;
Server = new NetServer(config);
Server.Start();
// attempt upnp port forwarding
Server.UPnP.ForwardPort(14242, "Durable sample test");
m_expectedReliableOrdered = new uint[3];
m_reliableOrderedCorrect = new int[3];
m_reliableOrderedErrors = new int[3];
m_expectedSequenced = new uint[3];
m_sequencedCorrect = new int[3];
m_sequencedErrors = new int[3];
Application.Idle += new EventHandler(AppLoop);
Application.Run(MainForm);
Server.Shutdown("App exiting");
}
示例3: RegionServer
/// <summary>
/// Constructor taking the path to the configuration file.
/// Starts the lidgren server to start listening for connections, and
/// initializes all data structres and such.
/// </summary>
/// <param name="configpath"></param>
public RegionServer(string configpath)
{
//Load this region server's junk from xml
XmlSerializer deserializer = new XmlSerializer(typeof(RegionConfig));
RegionConfig regionconfig = (RegionConfig)deserializer.Deserialize(XmlReader.Create(configpath));
//Create the server
var config = new NetPeerConfiguration(regionconfig.ServerName);
config.Port = regionconfig.ServerPort;
LidgrenServer = new NetServer(config);
LidgrenServer.Start();
//Initizlie our data structures
Characters = new Dictionary<Guid, Character>();
UserIdToMasterServer = new Dictionary<Guid, NetConnection>();
TeleportEnters = new List<TeleportEnter>(regionconfig.TeleportEnters);
TeleportExits = new List<TeleportExit>(regionconfig.TeleportExits);
ItemSpawns = new List<ItemSpawn>(regionconfig.ItemSpawns);
ItemSpawnIdGenerator = new UniqueId();
ItemSpawnsWaitingForSpawn = new Dictionary<ItemSpawn, DateTime>();
foreach(ItemSpawn spawn in ItemSpawns)
ItemSpawnIdGenerator.RegisterId(spawn.Id);
RegionId = regionconfig.RegionId;
}
示例4: 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();
}
示例5: SetUpConnection
public void SetUpConnection()
{
configuration = new NetPeerConfiguration("PingPong");
configuration.EnableMessageType(NetIncomingMessageType.WarningMessage);
configuration.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage);
configuration.EnableMessageType(NetIncomingMessageType.ErrorMessage);
configuration.EnableMessageType(NetIncomingMessageType.Error);
configuration.EnableMessageType(NetIncomingMessageType.DebugMessage);
configuration.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
configuration.EnableMessageType(NetIncomingMessageType.Data);
switch (networkRole)
{
case GamerNetworkType.Client:
Client = new NetClient(configuration);
Client.Start();
Client.Connect(new IPEndPoint(NetUtility.Resolve(IP), Convert.ToInt32(Port)));
break;
case GamerNetworkType.Server:
configuration.Port = Convert.ToInt32(Port);
Server = new NetServer(configuration);
Server.Start();
break;
default:
throw new ArgumentException("Network type was not set");
}
}
示例6: NetworkManager
public NetworkManager(int Port, string AppID)
{
Config = new NetPeerConfiguration(AppID);
Config.Port = Port;
Server = new NetServer(Config);
Server.Start();
}
示例7: 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();
}
示例8: 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!");
}
示例9: 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();
}
示例10: OnInitialise
protected override void OnInitialise()
{
Log.Info(String.Format("Initialising NetServer on Port {0}..", _config.Port));
OnIncomingMessage += LidgrenServer_OnIncomingMessage;
_config.AcceptIncomingConnections = true;
_server = new NetServer(_config);
_server.Start();
}
示例11: Main
private static void Main(string[] args)
{
var config = new NetPeerConfiguration("airgap")
{
Port = port,
MaximumConnections = 50,
ConnectionTimeout = 5f
};
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
var server = new NetServer(config);
server.Start();
Console.WriteLine("AudioGap Server Started");
waveOut.DeviceNumber = 0; // TODO: need an option for this
while (true)
{
NetIncomingMessage msg;
if ((msg = server.ReadMessage()) == null)
{
Thread.Sleep(1);
continue;
}
switch (msg.MessageType)
{
case NetIncomingMessageType.VerboseDebugMessage:
case NetIncomingMessageType.DebugMessage:
case NetIncomingMessageType.WarningMessage:
case NetIncomingMessageType.ErrorMessage:
Console.WriteLine(msg.ReadString());
break;
case NetIncomingMessageType.StatusChanged:
var status = (NetConnectionStatus)msg.ReadByte();
string reason = msg.ReadString();
Console.WriteLine("New status: " + status + " (" + reason + ")");
break;
case NetIncomingMessageType.ConnectionApproval:
SetupAudio(msg);
msg.SenderConnection.Approve();
break;
case NetIncomingMessageType.Data:
if (msg.SenderConnection.Status == NetConnectionStatus.Connected)
HandleAudioPacket(msg);
break;
default:
Console.WriteLine("Unhandled type: " + msg.MessageType);
break;
}
}
}
示例12: Initialize
private void Initialize()
{
mConfig.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
mConfig.Port = port;
mPeer = new NetServer(mConfig);
mPeer.Start();
mOutgoingMessage = mPeer.CreateMessage();
while(true) CheckForMessages();
}
示例13: Server
public Server()
{
NetPeerConfiguration config = new NetPeerConfiguration( "Server" );
config.Port = 14242;
instance = new NetServer( config );
instance.Start();
}
示例14: Server_Load
private void Server_Load(object sender, EventArgs e)
{
NetPeerConfiguration config = new NetPeerConfiguration("Testing");
config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
config.Port = 50001;
server = new NetServer(config);
server.Start();
}
示例15: NetworkServer
public NetworkServer()
{
var cfg = new NetConfiguration("aav.defense");
cfg.Address = IPAddress.Any;
cfg.Port = 52244;
cfg.AnswerDiscoveryRequests = true;
_srv = new NetServer(cfg);
_srv.Start();
}