(self, payload, binary=False)
Sends the given ``payload`` out.

        If ``payload`` is some bytes or a bytearray,
        then it is sent as a single message not fragmented.

        If ``payload`` is a generator, each chunk is sent as part of
        fragmented message.

        If ``binary`` is set, handles the payload as a binary message.
Sends the given ``payload`` out.
Sends the given payload out .
def send(self, payload, binary=False):
        """
        Sends the given ``payload`` out.

        If ``payload`` is some bytes or a bytearray,
        then it is sent as a single message not fragmented.

        If ``payload`` is a generator, each chunk is sent as part of
        fragmented message.

        If ``binary`` is set, handles the payload as a binary message.
        """
        if self.terminated:
            raise RuntimeError("Cannot send on a terminated websocket")

        message_sender = self.stream.binary_message if binary else self.stream.text_message

        if isinstance(payload, basestring) or isinstance(payload, bytearray):
            m = message_sender(payload).single(mask=self.stream.always_mask)
            self.sock.sendall(m)

        elif isinstance(payload, Message):
            data = payload.single(mask=self.stream.always_mask)
            self.sock.sendall(data)

        elif type(payload) == types.GeneratorType:
            bytes = next(payload)
            first = True
            for chunk in payload:
                self.sock.sendall(message_sender(bytes).fragment(first=first, mask=self.stream.always_mask))
                bytes = chunk
                first = False

            self.sock.sendall(message_sender(bytes).fragment(last=True, mask=self.stream.always_mask))

        else:
            raise ValueError("Unsupported type '%s' passed to send()" % type(payload))
def send ( self , payload , binary = False ) : if self . terminated : raise RuntimeError ( "Cannot send on a terminated websocket" ) message_sender = self . stream . binary_message if binary else self . stream . text_message if isinstance ( payload , basestring ) or isinstance ( payload , bytearray ) : m = message_sender ( payload ) . single ( mask = self . stream . always_mask ) self . sock . sendall ( m ) elif isinstance ( payload , Message ) : data = payload . single ( mask = self . stream . always_mask ) self . sock . sendall ( data ) elif type ( payload ) == types . GeneratorType : bytes = next ( payload ) first = True for chunk in payload : self . sock . sendall ( message_sender ( bytes ) . fragment ( first = first , mask = self . stream . always_mask ) ) bytes = chunk first = False self . sock . sendall ( message_sender ( bytes ) . fragment ( last = True , mask = self . stream . always_mask ) ) else : raise ValueError ( "Unsupported type '%s' passed to send()" % type ( payload ) )