<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def write(self, message, opcode=None, encode=True, **kw):
        '''Write a new ``message`` into the wire.

        It uses the :meth:`~.FrameParser.encode` method of the
        websocket :attr:`parser`.

        :param message: message to send, must be a string or bytes
        :param opcode: optional ``opcode``, if not supplied it is set to 1
            if ``message`` is a string, otherwise ``2`` when the message
            are bytes.
         '''
        if encode:
            message = self.parser.encode(message, opcode=opcode, **kw)
        result = self.connection.write(message)
        if opcode == 0x8:
            self.connection.close()
        return result