Engine-Pong/Game/Network/NetworkClient.cs

24 lines
661 B
C#

using LiteNetLib.Utils;
using Syntriax.Engine.Network.Abstract;
namespace Syntriax.Engine.Network;
public class NetworkClient : NetworkBase, INetworkCommunicatorClient
{
private readonly NetDataWriter netDataWriter = new();
public void Connect(string address, int port, string? password = null)
{
Manager.Start();
Manager.Connect(address, port, password ?? string.Empty);
}
public override void Send<T>(NetworkPacket<T> packet)
{
netDataWriter.Reset();
netPacketProcessor.Write(netDataWriter, packet);
Manager.FirstPeer.Send(netDataWriter, LiteNetLib.DeliveryMethod.ReliableOrdered);
}
}