/// <summary>
/// Closes the socket connection normally. This does not release the resources used by the
/// <see cref="AsyncTcpClient"/>.
/// </summary>
public void Disconnect()
{
if (tcpClient == null)
{
return;
}
try
{
if (tcpClient.Connected && tcpClient.Client.Connected)
{
tcpClient.Client.Disconnect(false);
}
}
catch (ObjectDisposedException)
{
// Already disposed, nothing to do
}
}
/// <summary>
/// Releases the managed and unmanaged resources used by the <see cref="AsyncTcpClient"/>.
/// Closes the connection to the remote host and disables automatic reconnecting.
/// </summary>
public void Dispose()
{
AutoReconnect = false;
tcpClient?.Dispose();
tcpClient = null;
stream = null;
}
https://github.com/ygoe/AsyncTcpClient/blob/58acf5f03be9691a171d31df0c7ebc87521311dc/AsyncTcpClient/AsyncTcpClient.cs#L284C4-L284C39
Only call if not disposed, present & connected ?