how show number of packet in my gui


how show number of packet in my gui



i have two pages one page is client and another gui,i need to display the number of packets after download file using read button, i used return in client file to call variable (rcv_total) and used insert in gui file but repeating downloading and gui hanging.



my client.py file


class TFTPClient(object):

def read(self, remote, local=None, mode='octet'):
''' Create a RRQ request to a server on open up a connectionless delivery of packets via udp datagrams. '''

try:
if not self.socket:
self.socket = socket(AF_INET, SOCK_DGRAM)

success = False

if not remote:
raise TFTPException("Remote file name cannot be empty.")

if not local:
local = remote # If no local file name supplied, just use the same on we are getting from the server

self.log("read", params=(remote, local, mode), msg="Initiating RRQ request to: %s port: %s" % (self.addr))

opcode, packetnr = self.opcodes['read'], 1 # get RRQ opcode and start with packet nr 1
snd_buffer = self.request_packet(remote, mode, opcode) # create RRQ packet

# send first RRQ packet
self.socket.sendto(snd_buffer, self.addr) # open a connection and send a udp datagram to a given host
(rcv_buffer, (host, port)) = self.socket.recvfrom(self.BLK_SIZE) # get response and addr_info
rcv_total, retry_count = len(rcv_buffer), 0



# Exec time of program
start_time = time.time()

# open a stream to write
with open(local, 'wb+') as f:
while True:
try:
if packetnr % 5000 == 0:
print("Total {0} received: {1}, execution time: {2} sec".format('KB', rcv_total / 1024, time.time() - start_time))

if not host and port:
raise TFTPException("Host and port are invalid: %s:%s" % (host, port))

if rcv_buffer[1] == self.opcodes['error']:
raise TFTPException(rcv_buffer[4:])

elif (((rcv_buffer[2] << 8) & 0xff00) + rcv_buffer[3]) == packetnr & 0xffff:
f.write(rcv_buffer[4:]) # write our byte data, without the header

# Last packet was sent
if self.BLK_SIZE > len(rcv_buffer):
break

# Normal, continue to read from server
else:

# Create ACK packet
snd_buffer = self.ack_packet(packetnr)
packetnr += 1

# Send ACK packet
self.socket.sendto(snd_buffer, (host, port)) # open a connection and send a udp datagram to a given host

# Get DATA packet and new TID
(rcv_buffer, (host, port)) = self.socket.recvfrom(self.BLK_SIZE) # get response and addr_info
rcv_total += len(rcv_buffer)



except Exception as err:
message = "Packetnr: {0}, retry count: {1}, header: {2}, error: {3}ntraceback: {4}"
self.log("read: exception", params=(remote, local, mode), msg=message.format(packetnr, retry_count, rcv_buffer[:4], err, traceback.format_exc()))

if self.TIME_OUT in err.args:
retry_count += 1

if retry_count >= self.MAX_RETRY_COUNT:
print("Retried max {0} times... leaving".format(retry_count))
break
else:
self.log("read: timeout exception", params=(remote, local, mode), msg=message.format(packetnr, retry_count, rcv_buffer[:4], err, traceback.format_exc()))

elif self.NOT_FOUND in err.args:
print("File %s does not exist!" % remote)

# Unknown exception
else:
self.log("read", params=(local, remote, mode), msg="Unknown exception: %s" % err)

**return (rcv_total) >>>this variable i need to call**



2 nd file



from client import TFTPClient



class Tftp_gui(TFTPClient):


def __init__(self, root):
self.host = tkinter.StringVar(root)
self.timeout=tkinter.StringVar(root)
self.browse_value = tkinter.StringVar()
self._label7 = tkinter.LabelFrame(root, text= "packet" )
self.packet1 = tkinter.Entry(self._label7, width = 8 )



def read_command(self):
c,file_name, alt_filename= TFTPClient(self._host.get(), self._port.get(),self.timeout.get()), self.remote_file.get(), self.alt_filename.get()
self.packet1.insert(0,c.read(file_name))
if c.read(file_name, file_name if len(alt_filename) is 0 else alt_filename):


if os.path.isfile(file_name):
print('Success')



def main():
try:
userinit()
except NameError:
pass


root = Tk()
window = Tftp_gui(root)
root.title('TftpClient')
root.resizable(width=FALSE, height=FALSE)

try:
run()
except NameError:
pass

root.protocol('WM_DELETE_WINDOW', root.quit)
root.mainloop()



if name == 'main':
main()



enter image description here





It is unclear what you are asking. Please consider rewording your question to be more concise, and provide a Minimal, Complete, and Verifiable example.
– OregonJim
Jun 29 at 18:29










By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift