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


Python Packet.getEncodedPacket方法代码示例

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


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

示例1: copyFromDFS

# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getEncodedPacket [as 别名]
def copyFromDFS(address, fname, path):
	""" Contact the metadata server to ask for the file blocks of
	    the file fname.  Get the data blocks from the data nodes.
	    Saves the data in path.
	"""

   	# Contact the metadata server to ask for information of fname
	sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	sock.connect(address)


	# Create a packet object to get block ids from meta data
	p = Packet()
	p.BuildGetPacket(fname)
	sock.sendall(p.getEncodedPacket())


	# If there is no error response, retreive the data blocks
	r = sock.recv(1024)
	p.DecodePacket(r)
	dnList = p.getDataNodes()


	# Create file to store data from blocks
	f = open(path, 'wb')


	# Get data blocks from data servers
	for dnode in dnList:
		# Contact the data node
		sockdn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		sockdn.connect((dnode[0], dnode[1]))


		# Create a packet object to get data from data node
		p.BuildGetDataBlockPacket(dnode[2])
		sockdn.sendall(p.getEncodedPacket())

		# Get the data size of the data that will be receive
		dsize = sockdn.recv(1024)
		dsize = int(dsize)

		sockdn.sendall("OK")


		# Get data in 1024 size parts
		data = ""
		while(len(data) < dsize):
			r = sockdn.recv(1024)
			data = data + r
			sockdn.sendall("OK")

		# Write data to file
		f.write(data)
		sockdn.close()


	f.close()
开发者ID:jesspagan,项目名称:dfs_project,代码行数:60,代码来源:copy.py

示例2: copyFromDFS

# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getEncodedPacket [as 别名]
def copyFromDFS(address, dfs_path, filename, password, crypto):
    """ Contact the metadata server to ask for the file blocks of
        the file fname.  Get the data blocks from the data nodes.
        Saves the data in path.
    """
    # Contact the metadata server to ask for information of fname

    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect(address)
    p = Packet()
    p.BuildGetPacket(dfs_path)
    sendall_with_size(sock, p.getEncodedPacket())

    # If there is no error response Retreive the data blocks

    # Save the file

    message = recv_with_size(sock)
    p.DecodePacket(message)
    #getDataNodes has ADDRESS, PORT, BLOCK_ID
    data_nodes = p.getDataNodes()

    """Not needed."""
    #In case the user specifies a diferent directory

    #filename = fname.split("/")

    #destination = "%s/%s" % (path, "copy_" + filename[-1])
    """Not needed."""

    wfile = open(filename, "w")
    for IP, PORT, BLOCK_ID in data_nodes:
        node_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        node_sock.connect((IP, PORT))

        p.BuildGetDataBlockPacket(BLOCK_ID)
        sendall_with_size(node_sock, p.getEncodedPacket())

        block = recv_with_size(node_sock)

        #added for decrypting
        if(crypto):
            decrpt_block = decrypt(password, block)

        else:
            decrpt_block = block

        wfile.write(decrpt_block)

        node_sock.close()

    wfile.close()
开发者ID:NamcoPro,项目名称:Distributed-File-System,代码行数:54,代码来源:copy.py

示例3: client

# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getEncodedPacket [as 别名]
def client(ip, port):

	# Contacts the metadata server and ask for list of files.
	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	s.connect((ip, port))

	# Creae a Packet and build it as a list packet
	# then send it to the metadata server
	packet = Packet()
	packet.BuildListPacket()
	s.sendall(packet.getEncodedPacket())

	# Now we take the response of the metadata server
	# the response is a packet with the list of files
	response = s.recv(1024)

	#print response
	
	if response == 'NAK':
		print 'there was an error with the request'
	else:
		packet.DecodePacket(response)

		# here I get the file array from the packet and
		# I will iterate to display the files and their size
		fileList = packet.getFileArray()
		#print fileList
		for f in fileList:
			print f[0], f[1], "bytes"
开发者ID:eduardogalindez,项目名称:DFS,代码行数:31,代码来源:ls.py

示例4: client

# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getEncodedPacket [as 别名]
def client(ip, port):

	# Contacts the metadata server and ask for list of files.
	sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #Creating socket

	try:
		sock.connect((ip, port)) #Connecting socket
	except:
		print 'Could not connect to the server. Are you sure it is on and that you have the right port?'

	p = Packet() #Making a packet
	p.BuildListPacket() #Building packet
	
	try:
		sock.sendall(p.getEncodedPacket()) #Sending encoded packet
	except:
		print 'Could not send the encoded packet!'

	files = sock.recv(1024) #Receiving list of files

	p.DecodePacket(files) #Decoding Packet

	try:
		for files, size in p.getFileArray():
			print files, size, ' bytes'
	except:
		print 'Could not read list of files.'
开发者ID:skytremor,项目名称:Distributed-File-System,代码行数:29,代码来源:ls.py

示例5: register

# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getEncodedPacket [as 别名]
def register(meta_ip, meta_port, data_ip, data_port):
	"""Creates a connection with the metadata server and
	   register as data node
	"""

	# Establish connection
	
	sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	
	try:
		sock.connect((meta_ip, meta_port))
		response = "NAK"
		sp = Packet()
		while response == "NAK":
			sp.BuildRegPacket(data_ip, data_port)
			sock.sendall(sp.getEncodedPacket())
			response = sock.recv(1024)

			if response == "DUP":
				print "Duplicate Registration"

		 	if response == "NAK":
				print "Registratation ERROR"
	except:
		print 'ERROR: Unable to connect to server!\nPlease make sure the meta-data server is online.'
		sys.exit(0)

	finally:
		sock.close()
开发者ID:skytremor,项目名称:Distributed-File-System,代码行数:31,代码来源:data-node.py

示例6: register

# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getEncodedPacket [as 别名]
def register(meta_ip, meta_port, data_ip, data_port):
    """Creates a connection with the metadata server and
       register as data node
    """

    # Establish connection
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((meta_ip, meta_port))

    #Wow. Everything was all here. Fucking Packets, man.
    try:
        response = "NAK"
        sp = Packet()
        while response == "NAK":
            sp.BuildRegPacket(data_ip, data_port)
            sendall_with_size(sock, sp.getEncodedPacket())
            response = recv_with_size(sock)

            if response == "DUP":
                print "Duplicate Registration"

            if response == "NAK":
                print "Registratation ERROR"

    finally:
        sock.close()
开发者ID:NamcoPro,项目名称:Distributed-File-System,代码行数:28,代码来源:data-node.py

示例7: register

# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getEncodedPacket [as 别名]
def register(meta_ip, meta_port, data_ip, data_port):
	"""Creates a connection with the metadata server and
	   register as data node
	"""

	# Establish connection
	sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	sock.connect((meta_ip, meta_port))
		

	# Register data_node to meta_data
	try:
		response = "NAK"
		sp = Packet()
		while response == "NAK":
			sp.BuildRegPacket(data_ip, data_port)
			sock.sendall(sp.getEncodedPacket())
			response = sock.recv(1024)

			if response == "DUP":
				print "Duplicate Registration"

		 	if response == "NAK":
				print "Registratation ERROR"


	finally:
		sock.close()
开发者ID:jesspagan,项目名称:dfs_project,代码行数:30,代码来源:data-node.py

示例8: handle_list

# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getEncodedPacket [as 别名]
	def handle_list(self, db):
		"""Get the file list from the database and send list to client"""
		try:
			# Fill code here
			packet = Packet()
			packet.BuildListResponse(db.GetFiles())
			self.request.sendall(packet.getEncodedPacket())
		except:
			self.request.sendall("NAK")	
开发者ID:skytremor,项目名称:Distributed-File-System,代码行数:11,代码来源:meta-data.py

示例9: handle_list

# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getEncodedPacket [as 别名]
	def handle_list(self, db):
		"""Get the file list from the database and send list to client"""
		try:
			# Fill code here
			response = Packet()
			response.BuildListResponse(db.GetFiles())
			self.request.sendall(response.getEncodedPacket()) 	
		except Exception as e:
			printExeption(e)
			self.request.sendall("NAK")	
开发者ID:JpGallegos,项目名称:simple_dfs,代码行数:12,代码来源:meta-data.py

示例10: handle_list

# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getEncodedPacket [as 别名]
    def handle_list(self, db):
        """Get the file list from the database and send list to client"""
        try:
            #Packet for the ls.py response
            list_p = Packet()
            #GetFiles() already sends the files in the neat format
            list_p.BuildListResponse(db.GetFiles())
            self.sendall_with_size(list_p.getEncodedPacket())

        except:
            print "Problem in handle_list()."
            self.sendall_with_size("NAK")
开发者ID:NamcoPro,项目名称:Distributed-File-System,代码行数:14,代码来源:meta-data.py

示例11: handle_list

# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getEncodedPacket [as 别名]
	def handle_list(self, db):
		"""Get the file list from the database and send list to client"""
		try:
			# list will contain the names and sizes of all the files
			List = db.GetFiles()
			# now create a build list packet and send it to the client
			packet = Packet()
			packet.BuildListResponse(List)
			self.request.sendall(packet.getEncodedPacket())

		except:
			self.request.sendall("NAK")	
开发者ID:eduardogalindez,项目名称:DFS,代码行数:14,代码来源:meta-data.py

示例12: handle_list

# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getEncodedPacket [as 别名]
	def handle_list(self, db):
		"""Get the file list from the database and send list to client"""
		try:
			sp = Packet()
			lfiles = []
			for file, size in db.GetFiles():
				lfiles.append((file, size))

			else:
				sp.BuildListResponse(lfiles)
				self.request.sendall(sp.getEncodedPacket())

		except:
			self.request.sendall("NAK")	
开发者ID:gallijs,项目名称:DFSv2,代码行数:16,代码来源:meta-data.py

示例13: handle_list

# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getEncodedPacket [as 别名]
	def handle_list(self, db):
		"""Get the file list from the database and send list to client"""

		try:
			# Search files information from data base
			dbfiles = db.GetFiles()

			# Create packet for sending to client
			p = Packet()
			p.BuildListResponse(dbfiles)

			# Sending encoded packet to list client
			self.request.sendall(p.getEncodedPacket())


		except:
			self.request.sendall("NAK")	
开发者ID:jesspagan,项目名称:dfs_project,代码行数:19,代码来源:meta-data.py

示例14: client

# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getEncodedPacket [as 别名]
def client(ip, port):

	# Contacts the metadata server and ask for list of files.
	sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	sock.connect((ip, port))

	# Creates a packet to ask the metadata to send the file list
	p = Packet()
	p.BuildListPacket()
	sock.sendall(p.getEncodedPacket())

	# Received the list of files and display the information
	r = sock.recv(1024)
		# print r, type(r)

	p.DecodePacket(r)
	filelist = p.getFileArray()

	for item in filelist:
		print item[0], item[1], "bytes"
开发者ID:jesspagan,项目名称:dfs_project,代码行数:22,代码来源:ls.py

示例15: client

# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getEncodedPacket [as 别名]
def client(ip, port):
    #socket for connecting to the metadata server
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((ip, port))

    #packet object used to interact with the metadata server
    p = Packet()
    #list command
    p.BuildListPacket()

    #sending the size and later the command
    message = p.getEncodedPacket()
    sendall_with_size(sock, message)

    #dealing with the metadata server's response
    response = recv_with_size(sock)
    p.DecodePacket(response)

    #get file array is a cool guy and has all the files if successful
    for filename, size in p.getFileArray():
        print filename, size, "bytes"

    sock.close()
开发者ID:NamcoPro,项目名称:Distributed-File-System,代码行数:25,代码来源:ls.py


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