当前位置: 首页>>代码示例>>Python>>正文


Python Packet.binary_blob方法代码示例

本文整理汇总了Python中packet.Packet.binary_blob方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.binary_blob方法的具体用法?Python Packet.binary_blob怎么用?Python Packet.binary_blob使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在packet.Packet的用法示例。


在下文中一共展示了Packet.binary_blob方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: transfer_file

# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import binary_blob [as 别名]
	def transfer_file(self, share_ID, file_name, return_address, start_offset=0, end_offset=999999999999, block_skip=1):
		"""Sends a piece of a file to a peer in pieces.
		Initiated by JSONRPC: get_file()
		start_offset: start sending file from this offset
		end_offset: if this bytes is reached, send no more.
		block_skip: send a block, then skip this many blocks, then send the next etc.
		"""
		#continue to send all file blocks
		full_file_path = os.path.join(self.storage_directory, share_ID, file_name)
		f = open(full_file_path, 'rb')
		f.seek(start_offset)
		block_size = 5
		file_offset = start_offset
		
		logging.debug('file_name: %s start_offset: %d, end_offset: %d' %(file_name, start_offset, end_offset))
		
		while (file_offset < end_offset):  #@TODO: stop sending if given signal from return_address
			logging.debug('file_offset: %d' %(file_offset))
			block_bytes = f.read(64*block_size)
			if block_bytes == "":
				logging.debug('no bytes read from file')
				break
			p_out_block = Packet()
			p_out_block.json_RPC_object = dict(jsonrpc="2.0", method="save_file_block", params=[1.0, None, [self.my_machine_ID, share_ID, file_name, file_offset]], )  #id=rpc_id
			p_out_block.binary_blob = block_bytes
			p_out_block.to_address = return_address
			
			self.send_block_choke(p_out_block, return_address, 3)
			
			time.sleep(0.002)
			file_offset+=block_size
		
		logging.debug('finished file transfer')
		f.close()
开发者ID:stevenleigh,项目名称:sib,代码行数:36,代码来源:jsonserver.py


注:本文中的packet.Packet.binary_blob方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。