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