/// <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;
}