def loseConnection(self, code=NORMAL, reason=""): if not self.disconnecting: data = packUShort(code) + reason.encode('utf8') frame = buildFrame(CLOSE, data, fin=True) self.parentTransport.write(frame) self.disconnecting = True self.parentTransport.loseConnection()
def _parseBuffer(self): for opcode, data, (statusCode, statusMessage), fin in parseFrames(self._buffer): if opcode == CLOSE: # Close the connection self.receiver.closeReceived(statusCode, statusMessage) self.transport.loseConnection() return elif opcode == PONG: pass # TODO - add ping functionality onto the protocol elif opcode == PING: self.transport.write(buildFrame(PONG, data)) else: self.receiver.frameReceived(opcode, data)
def _parseBuffer(self): for opcode, data, (statusCode, statusMessage), fin in parseFrames(self._buffer): if opcode == -1: self._buffer = data return if opcode == CLOSE: # Close the connection self.receiver.closeReceived(statusCode, statusMessage) self.transport.loseConnection() return elif opcode == PONG: pass # TODO - add ping functionality onto the protocol elif opcode == PING: self.transport.write(buildFrame(PONG, data, fin=True)) else: self.receiver.frameReceived(opcode, data, fin)
def sendFrame(self, opcode, data, fin): packet = buildFrame(opcode, data, fin=fin) self.parentTransport.write(packet)
def sendFrame(self, opcode, data): packet = buildFrame(opcode, data) self.parentTransport.write(packet)