コード例 #1
0
 public Task CloseAsync()
 {
     if (_socket == null)
     {
         throw new InvalidOperationException("Close failed, must connect first.");
     }
     else
     {
         _tokenSource.Cancel();
         _tokenSource.Dispose();
         _socket.Abort();
         _socket.Dispose();
         _socket = null;
         OnClosed?.Invoke(ServerCloseReason.ClosedByClient);
         return(Task.CompletedTask);
     }
 }