I'm trying to get Lidgren working, however my client won't connect to the server for some reason. Server doesn't receive any messages, so I'm guessing the problem is entirely with the client. Client gets a "StatusChanged" message, but client never connects. Full source here:
Server
static void Main(string[] args)
{
Console.WriteLine("Otrera Server");
NetPeerConfiguration config = new NetPeerConfiguration("OtreraServer");
config.Port = 14242;
config.MaximumConnections = 5;
NetServer server = new NetServer(config);
server.Start();
if(server.Status == NetPeerStatus.Running)
{
Console.WriteLine("Server is running on port " + config.Port);
}
else
{
Console.WriteLine("Server not started...");
}
NetIncomingMessage msg;
while(true)
{
server.WaitMessage(500);
while((msg = server.ReadMessage()) != null)
{
switch(msg.MessageType)
{
case NetIncomingMessageType.ConnectionApproval:
msg.SenderConnection.Approve();
Console.WriteLine("Connection Approved");
break;
case NetIncomingMessageType.StatusChanged:
Console.WriteLine("Status changed");
break;
case NetIncomingMessageType.Data:
Console.WriteLine("Recieved message");
break;
default:
Console.WriteLine("Unkown message of type"+msg.MessageType.ToString());
break;
}
}
}
}
Client:
if(client == null)
{
NetPeerConfiguration config = new NetPeerConfiguration("OtreraClient");
client = new NetClient(config);
client.Start();
Thread.Sleep(500);
client.Connect("localhost", 14242);
Thread.Sleep(500);
}
NetIncomingMessage msg;
while((msg = client.ReadMessage()) != null)
{
switch(msg.MessageType)
{
case NetIncomingMessageType.DiscoveryResponse:
//client.Connect(msg.SenderEndPoint);
break;
case NetIncomingMessageType.Error:
Console.WriteLine("Connection error");
break;
case NetIncomingMessageType.StatusChanged:
Console.WriteLine("Status changed");
break;
case NetIncomingMessageType.Data:
Console.WriteLine("Received message");
break;
case NetIncomingMessageType.DebugMessage:
Console.WriteLine("DebugMessage");
break;
case NetIncomingMessageType.WarningMessage:
Console.WriteLine("Warning message");
break;
}