Skip to content
This repository has been archived by the owner on Feb 25, 2020. It is now read-only.

Add docs for IClient #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion Networker/Client/Abstractions/IClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,70 @@ namespace Networker.Client.Abstractions
{
public interface IClient
{
/// <summary>
/// Occurs when the client is connected.
/// </summary>
EventHandler<Socket> Connected { get; set; }

/// <summary>
/// Occurs when the client is disconnected.
/// </summary>
EventHandler<Socket> Disconnected { get; set; }

/// <summary>
/// Serialize and send a Tcp packet.
/// </summary>
/// <typeparam name="T">The passed type.</typeparam>
/// <param name="packet">The packet.</param>
void Send<T>(T packet);
// void Send(byte[] packet);

/// <summary>
/// Send a raw byte array via Tcp packet.
/// </summary>
/// <remarks>
/// Keep in mind that Networker Server require the packet header,
/// which is handled by the <see cref="Common.Abstractions.IPacketSerialiser"/>.
///
/// So always recommended to use <see cref="Send{T}(T)"/> instead.
/// </remarks>
/// <param name="packet">The packet byte array.</param>
void Send(byte[] packet);

/// <summary>
/// Serialize and send a Udp packet.
/// </summary>
/// <typeparam name="T">The passed type.</typeparam>
/// <param name="packet">The packet.</param>
void SendUdp<T>(T packet);

/// <summary>
/// Send a raw byte array via Udp packet.
/// </summary>
/// <remarks>
/// Keep in mind that Networker Server require the packet header,
/// which is handled by the <see cref="Common.Abstractions.IPacketSerialiser"/>.
///
/// So always recommended to use <see cref="SendUdp{T}(T)"/> instead.
/// </remarks>
/// <param name="packet">The packet byte array.</param>
void SendUdp(byte[] packet);

/// <summary>
/// Send a ping to the server.
/// </summary>
/// <param name="timeout">The amount of time until timout.</param>
/// <returns>Returns -1 if unsuccessful; Otherwise the roundtrip time.</returns>
long Ping(int timeout = 10000);

/// <summary>
/// Connect to the Server.
/// </summary>
/// <returns></returns>
ConnectResult Connect();

/// <summary>
/// Close the connection to the server.
/// </summary>
void Stop();
}
}
13 changes: 11 additions & 2 deletions Networker/Client/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public class Client : IClient
private UdpClient udpClient;
private IPEndPoint udpEndpoint;

/// <inheritdoc />
public EventHandler<Socket> Connected { get; set; }

/// <inheritdoc />
public EventHandler<Socket> Disconnected { get; set; }

public Client(ClientBuilderOptions options,
Expand Down Expand Up @@ -96,7 +99,10 @@ public long Ping(int timeout)
}

/// <inheritdoc />
public void Send<T>(T packet) => Send(this.packetSerialiser.Serialise(packet));
public void Send<T>(T packet)
{
Send(this.packetSerialiser.Serialise(packet));
}

/// <inheritdoc />
public void Send(byte[] packet)
Expand All @@ -110,7 +116,10 @@ public void Send(byte[] packet)
}

/// <inheritdoc />
public void SendUdp<T>(T packet) => SendUdp(this.packetSerialiser.Serialise(packet));
public void SendUdp<T>(T packet)
{
SendUdp(this.packetSerialiser.Serialise(packet));
}

/// <inheritdoc />
public void SendUdp(byte[] packet)
Expand Down