1
0
mirror of https://github.com/oliverbooth/TcpDotNet synced 2024-11-10 02:35:43 +00:00
TcpDotNet/TcpDotNet.ClientIntegrationTest/Program.cs

27 lines
846 B
C#
Raw Normal View History

2022-05-18 16:39:48 +01:00
using System.Net;
using TcpDotNet;
using TcpDotNet.Protocol;
using TcpDotNet.Protocol.Packets.ClientBound;
using TcpDotNet.Protocol.Packets.ServerBound;
using var client = new ProtocolClient();
client.RegisterPacketHandler(PacketHandler<PongPacket>.Empty);
await client.ConnectAsync(IPAddress.IPv6Loopback, 1234);
Console.WriteLine($"Connected to {client.RemoteEndPoint}");
Console.WriteLine("Sending ping packet...");
var ping = new PingPacket();
await client.SendPacketAsync(ping);
Console.WriteLine("Waiting for response...");
Packet? response = await client.ReadNextPacketAsync();
if (response is PongPacket pong)
{
Console.WriteLine("Received pong packet");
Console.WriteLine(pong.Payload.SequenceEqual(ping.Payload) ? "Payload matches" : "Payload does not match");
}
else
{
Console.WriteLine("Received unknown packet");
}