本文整理汇总了C#中Lidgren.Network.NetServer.Recycle方法的典型用法代码示例。如果您正苦于以下问题:C# NetServer.Recycle方法的具体用法?C# NetServer.Recycle怎么用?C# NetServer.Recycle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetServer
的用法示例。
在下文中一共展示了NetServer.Recycle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
NetPeerConfiguration config = new NetPeerConfiguration("LidgrenTestServer");
config.Port = 14242;
config.MaximumConnections = 200;
NetServer server = new NetServer(config);
server.Start();
NetIncomingMessage msg;
while(true)
{
if((msg = server.ReadMessage()) != null)
{
Console.WriteLine(msg.ReadString());
server.Recycle(msg);
}
Thread.Sleep(20);
}
}
示例2: DispatchIM
/// <summary>
///
/// </summary>
/// <param name="message"></param>
void DispatchIM ( GameTime gameTime, SnapshotQueue queue, NetServer server )
{
NetIncomingMessage msg;
while ((msg = server.ReadMessage()) != null)
{
switch (msg.MessageType)
{
case NetIncomingMessageType.VerboseDebugMessage:Log.Debug ("SV Net: " + msg.ReadString()); break;
case NetIncomingMessageType.DebugMessage: Log.Verbose ("SV Net: " + msg.ReadString()); break;
case NetIncomingMessageType.WarningMessage: Log.Warning ("SV Net: " + msg.ReadString()); break;
case NetIncomingMessageType.ErrorMessage: Log.Error ("SV Net: " + msg.ReadString()); break;
case NetIncomingMessageType.ConnectionLatencyUpdated:
if (Game.Network.ShowLatency) {
float latency = msg.ReadFloat();
Log.Verbose("...SV ping - {0} {1,6:0.00} ms", msg.SenderEndPoint, (latency*1000) );
}
break;
case NetIncomingMessageType.DiscoveryRequest:
Log.Message("Discovery request from {0}", msg.SenderEndPoint.ToString() );
var response = server.CreateMessage( ServerInfo() );
server.SendDiscoveryResponse( response, msg.SenderEndPoint );
break;
case NetIncomingMessageType.ConnectionApproval:
var userGuid = msg.SenderConnection.GetHailGuid();
var userInfo = msg.SenderConnection.GetHailUserInfo();
var reason = "";
var approve = ApproveClient( userGuid, userInfo, out reason );
if (approve) {
msg.SenderConnection.Approve( server.CreateMessage( ServerInfo() ) );
} else {
msg.SenderConnection.Deny( reason );
}
break;
case NetIncomingMessageType.StatusChanged:
DispatchStatusChange( msg );
break;
case NetIncomingMessageType.Data:
DispatchDataIM( gameTime, queue, msg );
break;
default:
Log.Warning("SV: Unhandled type: " + msg.MessageType);
break;
}
server.Recycle(msg);
}
}