本文整理汇总了Python中Packet.getFileArray方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.getFileArray方法的具体用法?Python Packet.getFileArray怎么用?Python Packet.getFileArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet
的用法示例。
在下文中一共展示了Packet.getFileArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: client
# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getFileArray [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.'
示例2: client
# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getFileArray [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"
示例3: client
# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getFileArray [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"
示例4: client
# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getFileArray [as 别名]
def client(ip, port):
# Contacts the metadata server and ask for list of files.
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
p = Packet()
p.BuildListPacket()
sock.connect((ip, port))
sock.sendall(p.getEncodedPacket())
msg = sock.recv(1024)
if msg != "NAK":
p.DecodePacket(msg)
for f, size in p.getFileArray():
print f, size
else:
print "Not Acknowledged"
finally:
sock.close()
示例5: client
# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getFileArray [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()
示例6: Packet
# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import getFileArray [as 别名]
except socket.error, e:
print "Could not connect with server.\n %s"%e
sys.exit(1)
print "Connected to metadata server."
try:
response = "NAK"
sp = Packet()
while response == "NAK":
sp.BuildListPacket()
sock.sendall(sp.getEncodedPacket())
response = sock.recv(1024)
if response != "NAK":
sp.DecodePacket(response)
lfiles = sp.getFileArray()
if not lfiles:
print "There are no files."
else:
for i in lfiles:
print i[0], str(i[1]) + " Bytes"
finally:
sock.close()
if __name__ == "__main__":
META_PORT = 8000
cmd = sys.argv[1]