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


Python Packet类代码示例

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


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

示例1: register

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,代码行数:26,代码来源:data-node.py

示例2: createPacket

 def createPacket(self):
     message = "Packet " + str(self.currentPacketID) + "'s data goes here!"
     newPacket = Packet(self.currentPacketID, now(), self.ID, 
                        self.destinationID, False, False, message, self.globs)
     self.currentPacketID += 1     
     activate(newPacket, newPacket.run())
     return newPacket
开发者ID:liquidy,项目名称:CS-143-Project,代码行数:7,代码来源:Devices.py

示例3: register

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,代码行数:28,代码来源:data-node.py

示例4: createAckPacket

 def createAckPacket(self):
     message = "Acknowledgement packet " + str(self.currentPacketIDToAck) + "'s data goes here!"
     # create the packet object with the needed ack packet id, source id, etc.
     newPacket = Packet(self.currentPacketIDToAck, now(), self.ID, 
                        self.sourceID, False, True, message, self.globs)
     activate(newPacket, newPacket.run())
     return newPacket    
开发者ID:liquidy,项目名称:CS-143-Project,代码行数:7,代码来源:Devices.py

示例5: register

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,代码行数:29,代码来源:data-node.py

示例6: initiateReroute

 def initiateReroute(self):
     self.rerouting = True
     self.haveData = [False] * self.networkSize
     self.haveData[self.ID] = True
     self.haveAck = [False] * self.networkSize
     self.haveAck[self.ID] = True
     
     # calculate delayData
     self.delayData = []
     for i in range(self.networkSize):
         delays = self.delays[i]
         if delays != []:
             self.delayData.append((self.ID, i, sum(delays)/float(len(delays))))
         self.delays[i] = []
         
     self.updateNetwork(self.delayData)
     
     # broadcast rerouting signal with new delayData
     for i in range(self.networkSize):
         if i is not self.ID:
             if not (self.globs.NODES[i][1] or self.globs.NODES[i][2]): # if device i is a router
                 pkt = Packet("Delay Data at %d" % (self.ID), now(), self.ID, i, True, False, ("reroute", self.delayData), self.globs)
                 activate(pkt, pkt.run())
                 self.sendPacket(pkt, self.routingTable[i])
             else: # device is not a router, so don't need to communicate with it
                 self.haveData[i] = True
                 self.haveAck[i] = True
开发者ID:liquidy,项目名称:CS-143-Project,代码行数:27,代码来源:Devices.py

示例7: client

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,代码行数:29,代码来源:ls.py

示例8: client

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,代码行数:27,代码来源:ls.py

示例9: copyFromDFS

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,代码行数:58,代码来源:copy.py

示例10: handle_list

	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,代码行数:9,代码来源:meta-data.py

示例11: handle_list

	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,代码行数:10,代码来源:meta-data.py

示例12: handle

 def handle(self,now,event):
     if event == 'generate':
         if (now - self.start) > self.duration:
             return
             
         packet = Packet(src=self.node.name, dst='null')
         packet.load = self.mean_load
         packet.util = self.util
         self.scheduler.add(time=now, event=packet, handler=self.node.handle_message)
         now += random.expovariate(self.mean_load)
         self.scheduler.add(time=now, event='generate', handler=self.handle)
开发者ID:andmkent-zz,项目名称:pynet,代码行数:11,代码来源:Gen.py

示例13: handle_list

	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,代码行数:12,代码来源:meta-data.py

示例14: handle_list

    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,代码行数:12,代码来源:meta-data.py

示例15: copyFromDFS

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,代码行数:52,代码来源:copy.py


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