mirror of
https://github.com/oliverbooth/TcpDotNet
synced 2024-11-09 23:05:41 +00:00
refactor!: remove TSend generic parameter from SendAndReceiveAsync
This commit is contained in:
parent
7b74e1f3e5
commit
e7dfe97c6d
@ -1,4 +1,4 @@
|
||||
using System.Net;
|
||||
using System.Net;
|
||||
using TcpDotNet;
|
||||
using TcpDotNet.ClientIntegrationTest;
|
||||
using TcpDotNet.ClientIntegrationTest.PacketHandlers;
|
||||
@ -17,7 +17,7 @@ Console.WriteLine($"Connected to {client.RemoteEndPoint}. My session is {client.
|
||||
|
||||
var ping = new PingPacket();
|
||||
Console.WriteLine($"Sending ping packet with payload: {BitConverter.ToString(ping.Payload)}");
|
||||
var pong = await client.SendAndReceiveAsync<PingPacket, PongPacket>(ping);
|
||||
var pong = await client.SendAndReceiveAsync<PongPacket>(ping);
|
||||
|
||||
Console.WriteLine($"Received pong packet with payload: {BitConverter.ToString(pong.Payload)}");
|
||||
Console.WriteLine(pong.Payload.SequenceEqual(ping.Payload) ? "Payload matches!" : "Payload does not match!");
|
||||
|
@ -221,15 +221,13 @@ public abstract class BaseClientNode : Node
|
||||
/// </summary>
|
||||
/// <param name="packetToSend">The packet to send.</param>
|
||||
/// <param name="cancellationToken">A cancellation token that can be used to cancel the asynchronous operation.</param>
|
||||
/// <typeparam name="TSend">The type of the packet to send.</typeparam>
|
||||
/// <typeparam name="TReceive">The type of the packet to return.</typeparam>
|
||||
/// <returns>The received packet.</returns>
|
||||
/// <remarks>
|
||||
/// This method will consume all incoming packets, raising their associated handlers if such packets are recognised.
|
||||
/// </remarks>
|
||||
public async Task<TReceive> SendAndReceiveAsync<TSend, TReceive>(TSend packetToSend,
|
||||
public async Task<TReceive> SendAndReceiveAsync<TReceive>(Packet packetToSend,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TSend : Packet
|
||||
where TReceive : Packet
|
||||
{
|
||||
var attribute = typeof(TReceive).GetCustomAttribute<PacketAttribute>();
|
||||
|
@ -96,7 +96,7 @@ public sealed class ProtocolClient : BaseClientNode
|
||||
State = ClientState.Handshaking;
|
||||
var handshakeRequest = new HandshakeRequestPacket(ProtocolVersion);
|
||||
var handshakeResponse =
|
||||
await SendAndReceiveAsync<HandshakeRequestPacket, HandshakeResponsePacket>(handshakeRequest, cancellationToken);
|
||||
await SendAndReceiveAsync<HandshakeResponsePacket>(handshakeRequest, cancellationToken);
|
||||
|
||||
if (handshakeResponse.HandshakeResponse != HandshakeResponse.Success)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user