<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 async def close(self, code: int = 1006, reason: str = "Connection closed"):
 """ Closes the websocket. """

        if self._closed:
            return

        self._closed = True

        if self._scope is not None:
            await self._scope.cancel()
            # cancel any outstanding listeners

        data = self._connection.send(CloseConnection(code=code, reason=reason))
        await self._sock.send_all(data)

        # No, we don't wait for the correct reply
        await self._sock.close()