From 712273dd141b883c93cea7d39aa51e48de3c589f Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Thu, 26 Apr 2018 01:25:41 +0200 Subject: [PATCH] File transfer example --- Examples/Filetransfer.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Examples/Filetransfer.py b/Examples/Filetransfer.py index d902853..87d8a8e 100644 --- a/Examples/Filetransfer.py +++ b/Examples/Filetransfer.py @@ -83,6 +83,8 @@ def client_connected(link): if os.path.isdir(serve_path): RNS.log("Client connected, sending file list...") + link.link_closed_callback(client_disconnected) + # We pack a list of files for sending in a packet data = umsgpack.packb(list_files()) @@ -109,6 +111,9 @@ def client_connected(link): RNS.log("Client connected, but served path no longer exists!", RNS.LOG_ERROR) link.teardown() +def client_disconnected(link): + RNS.log("Client disconnected") + def client_request(message, packet): global serve_path if message in list_files(): @@ -235,7 +240,7 @@ def download(filename): # to select which files to download, or quit menu_mode = None def menu(): - global server_files + global server_files, server_link # Wait until we have a filelist while len(server_files) == 0: time.sleep(0.1) @@ -266,6 +271,9 @@ def menu(): except: pass + if should_quit: + server_link.teardown() + # Prints out menus or screens for the # various states of the client program. # It's simple and quite uninteresting. @@ -393,6 +401,8 @@ def link_closed(link): RNS.log("The link was closed by the server, exiting now") else: RNS.log("Link closed, exiting now") + + time.sleep(1.5) os._exit(0) # When RNS detects that the download has