Клиент-серверная система Lidgren не подключается к локальной сети
Я только начал изучать Lidgren и настроить простую систему клиент-сервер, основанную на предоставленных примерах, однако, в отличие от этих примеров, моя установка не будет подключаться к той же сети. Мне было просто интересно, если кто-нибудь может сказать мне, что не так с моим кодом. Для справки, я также использую MonoGame.
MTSClient.cs
using System;
using System.Threading;
using Lidgren.Network;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace MTS
{
public class MTSClient : Game
{
private GraphicsDeviceManager graphics;
private SpriteBatch spriteBatch;
private NetClient client;
public MTSClient()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
Window.Title = "MTS";
graphics.IsFullScreen = false;
IsMouseVisible = true;
NetPeerConfiguration config = new NetPeerConfiguration("MTS");
client = new NetClient(config);
Connect();
}
private void Connect()
{
client.Start();
NetOutgoingMessage hail = client.CreateMessage("Hail companion!");
client.Connect("127.0.0.1", 25565, hail);
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
//TODO: use this.Content to load your game content here
}
protected override void Update(GameTime gameTime)
{
// For Mobile devices, this logic will close the Game when the Back button is pressed
// Exit() is obsolete on iOS
#if !__IOS__ && !__TVOS__
if (GamePad.GetState (PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
Keyboard.GetState().IsKeyDown(Keys.Escape))
{
Exit();
}
#endif
// TODO: Add your update logic here
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(new Color(10, 10, 10));
//TODO: Add your drawing code here
base.Draw(gameTime);
}
}
}
MTSServer.cs
using Lidgren.Network;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MTS
{
public class Program
{
private static bool running = false;
private static Logger logger;
private static NetServer server;
public static void Main(string[] args)
{
logger = new Logger(true);
NetPeerConfiguration config = new NetPeerConfiguration("MTS");
config.MaximumConnections = 100;
config.Port = 25565;
server = new NetServer(config);
running = true;
while (running)
{
NetIncomingMessage message = server.ReadMessage();
if (message != null)
{
switch (message.MessageType)
{
case NetIncomingMessageType.StatusChanged:
NetConnectionStatus status = (NetConnectionStatus)message.ReadByte();
string reason = message.ReadString();
logger.Info(NetUtility.ToHexString(message.SenderConnection.RemoteUniqueIdentifier) + " Status: " + status + " Reason: " + reason);
if(status == NetConnectionStatus.Connected)
logger.Info("Remote hail from " + NetUtility.ToHexString(message.SenderConnection.RemoteUniqueIdentifier) + ": " + message.SenderConnection.RemoteHailMessage.ReadString());
break;
}
server.Recycle(message);
}
}
}
}
}