1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-06 02:11:06 +09:00
Files
lidgren-network-gen3/Samples/LibraryTestSamples/GarbageThrowerSample/Server/Program.cs
lidgren d2ae3cf41d BREAKING CHANGE: NatIntroductionSuccess is now DISABLED by default; you must enable it using EnableMessageType
Added GarbageThrowerSample - a small library sample that sends random and semi-random data to detect problems
Made lots of changes that caused exceptions when malformed data was received
2014-07-31 14:55:50 +00:00

59 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;
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;
}
}
}
}
}
}