code: def close(self, code: int = None, reason: str = None) -> None:
          
          if not self.server_terminated:
              if not self.stream.closed():
                  if code is None and reason is not None:
                      code = 1000  # "normal closure" status code
                  if code is None:
                      close_data = b""
                  else:
                      close_data = struct.pack(">H", code)
                  if reason is not None:
                      close_data += utf8(reason)
                  try:
                      self._write_frame(True, 0x8, close_data)
                  except StreamClosedError:
                      self._abort()
              self.server_terminated = True
          if self.client_terminated:
              if self._waiting is not None:
                  self.stream.io_loop.remove_timeout(self._waiting)
                  self._waiting = None
              self.stream.close()
          elif self._waiting is None:
              # Give the client a few seconds to complete a clean shutdown,
              # otherwise just close the connection.
              self._waiting = self.stream.io_loop.add_timeout(
                  self.stream.io_loop.time() + 5, self._abort
              )
docs: Closes the WebSocket connection.