Exemple #1
0
    def _send_ws_data(self, data):
        self._semaphore_send.acquire()
        try:
            bts = utils.Bytes()
            b0 = 0
            b0 |= 1 << 7
            b0 |= 0x2 % 128
            length = len(data)
            if length <= 125:
                bts.append_byte(b0)
                bts.append_byte(0x80 | length)
            elif length <= 0xFFFF:
                bts.append_byte(b0)
                bts.append_byte(0xFE)
                bts.append_byte(length >> 8 & 0xFF)
                bts.append_byte(length & 0xFF)
            else:
                bts.append_byte(b0)
                bts.append_byte(0xFF)
                bts.append_int(length)

            rnd = 0
            bts.append_int(rnd)
            bts.append_bytes(data)
            if self._sock is None:
                raise Exception('connection closed.')
            utils.socket_sendall(self._sock, bts, 0, len(bts))
        finally:
            self._semaphore_send.release()
Exemple #2
0
 def _send_ws_data(self, data):
     self._semaphore_send.acquire()
     try:
         b0 = 0
         b0 |= 1 << 7
         b0 |= 0x2 % 128
         length = len(data)
         rnd = 0
         if length <= 125:
             data.insert_byte(0, b0)
             data.insert_byte(1, 0x80 | length)
             data.insert_int(2, rnd)
         elif length <= 0xFFFF:
             data.insert_byte(0, b0)
             data.insert_byte(1, 0xFE)
             data.insert_byte(2, length >> 8 & 0xFF)
             data.insert_byte(3, length & 0xFF)
             data.insert_int(4, rnd)
         else:
             data.insert_byte(0, b0)
             data.insert_byte(1, 0xFF)
             data.insert_int(2, length)
             data.insert_int(3, rnd)
         if self._sock is None:
             raise Exception('connection closed.')
         utils.socket_sendall(self._sock, data)
     finally:
         self._semaphore_send.release()
Exemple #3
0
 def _send_ws_data(self, data):
     if self._sock is None:
         raise Exception('connection closed.')
     data.encode_ws_data()
     self._lock_send.acquire()
     try:
         utils.socket_sendall(self._sock, data)
     finally:
         self._lock_send.release()
Exemple #4
0
 def _send_ws_ping(self):
     if self._sock is None:
         raise Exception('connection closed.')
     bts = utils.Bytes()
     bts.encode_ws_ping()
     self._lock_send.acquire()
     try:
         utils.socket_sendall(self._sock, bts)
     finally:
         self._lock_send.release()
Exemple #5
0
 def _send_ws_ping(self):
     self._semaphore_send.acquire()
     try:
         bts = utils.Bytes()
         b0 = 0
         b0 |= 1 << 7
         b0 |= 0x9 % 128
         bts.append_byte(b0)
         bts.append_byte(0x80 | 0)
         rnd = 0  #random.randint(0,2147483647)
         bts.append_int(rnd)
         if self._sock is None:
             raise Exception('connection closed.')
         utils.socket_sendall(self._sock, bts, 0, len(bts))
     finally:
         self._semaphore_send.release()