using System.Net;
using System.Net.Sockets;
namespace KianaBH.KcpSharp.Base;
///
/// Helper methods to create socket transports for KCP conversations.
///
public static class KcpSocketTransport
{
///
/// Create a socket transport for KCP covnersation.
///
/// The udp listener instance.
/// The remote endpoint.
/// The conversation ID.
/// The options of the .
/// The created socket transport instance.
public static IKcpTransport CreateConversation(UdpClient listener, IPEndPoint endPoint,
long conversationId, KcpConversationOptions? options)
{
if (listener is null) throw new ArgumentNullException(nameof(listener));
if (endPoint is null) throw new ArgumentNullException(nameof(endPoint));
return new KcpSocketTransportForConversation(listener, endPoint, conversationId, options);
}
///
/// Create a socket transport for KCP covnersation with no conversation ID.
///
/// The udp listener instance.
/// The remote endpoint.
/// The options of the .
/// The created socket transport instance.
public static IKcpTransport CreateConversation(UdpClient listener, IPEndPoint endPoint,
KcpConversationOptions? options)
{
if (listener is null) throw new ArgumentNullException(nameof(listener));
if (endPoint is null) throw new ArgumentNullException(nameof(endPoint));
return new KcpSocketTransportForConversation(listener, endPoint, null, options);
}
///
/// Create a socket transport for raw channel.
///
/// The udp listener instance.
/// The remote endpoint.
/// The conversation ID.
/// The options of the .
/// The created socket transport instance.
public static IKcpTransport CreateRawChannel(UdpClient listener, IPEndPoint endPoint,
long conversationId, KcpRawChannelOptions? options)
{
if (listener is null) throw new ArgumentNullException(nameof(listener));
if (endPoint is null) throw new ArgumentNullException(nameof(endPoint));
return new KcpSocketTransportForRawChannel(listener, endPoint, conversationId, options);
}
///
/// Create a socket transport for raw channel with no conversation ID.
///
/// The udp listener instance.
/// The remote endpoint.
/// The options of the .
/// The created socket transport instance.
public static IKcpTransport CreateRawChannel(UdpClient listener, IPEndPoint endPoint,
KcpRawChannelOptions? options)
{
if (listener is null) throw new ArgumentNullException(nameof(listener));
if (endPoint is null) throw new ArgumentNullException(nameof(endPoint));
return new KcpSocketTransportForRawChannel(listener, endPoint, null, options);
}
///
/// Create a socket transport for multiplex connection.
///
/// The udp listener instance.
/// The maximum packet size that can be transmitted over the socket.
///
public static IKcpTransport CreateMultiplexConnection(UdpClient listener, int mtu)
{
if (listener is null) throw new ArgumentNullException(nameof(listener));
return new KcpSocketTransportForMultiplexConnection