1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-14 22:26:29 +09:00
Files
lidgren-network-gen3/Samples/LibraryTestSamples/GarbageThrowerSample/Server/Program.cs
2014-11-04 08:06:40 +00:00

61 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using Lidgren.Network;
namespace Server
{
class Program
{
static void Main(string[] args)
{
NetPeerConfiguration config = new NetPeerConfiguration("garbagethrower");
config.MaximumConnections = 1;
config.Port = 14242;
config.PingInterval = 2.0f;
config.ConnectionTimeout = 2.0f;
var server = new NetServer(config);
server.Start();
while (true)
{
NetIncomingMessage msg;
while ((msg = server.ReadMessage()) != null)
{
switch (msg.MessageType)
{
case NetIncomingMessageType.StatusChanged:
var status = (NetConnectionStatus)msg.ReadByte();
var reason = msg.ReadString();
Console.WriteLine("New status: " + status + " (" + reason + ")");
break;
case NetIncomingMessageType.WarningMessage:
case NetIncomingMessageType.VerboseDebugMessage:
case NetIncomingMessageType.ErrorMessage:
case NetIncomingMessageType.DebugMessage:
var str = msg.ReadString();
if (str.StartsWith("Malformed packet; stated") ||
str.StartsWith("Received unhandled library message") ||
str.StartsWith("Unexpected NetMessageType"))
break; // we'll get a bunch of these and we're fine with that
Console.WriteLine(msg.MessageType + ": " + str);
break;
case NetIncomingMessageType.Data:
Console.WriteLine("Received " + msg.LengthBits + " bits of data");
break;
case NetIncomingMessageType.UnconnectedData:
Console.WriteLine("Received " + msg.LengthBits + " bits of unconnected data");
break;
default:
Console.WriteLine("Received " + msg.MessageType);
break;
}
}
}
}
}
}