mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-26 15:30:18 +00:00
File transfer example
This commit is contained in:
parent
77da69c37d
commit
712273dd14
@ -83,6 +83,8 @@ def client_connected(link):
|
|||||||
if os.path.isdir(serve_path):
|
if os.path.isdir(serve_path):
|
||||||
RNS.log("Client connected, sending file list...")
|
RNS.log("Client connected, sending file list...")
|
||||||
|
|
||||||
|
link.link_closed_callback(client_disconnected)
|
||||||
|
|
||||||
# We pack a list of files for sending in a packet
|
# We pack a list of files for sending in a packet
|
||||||
data = umsgpack.packb(list_files())
|
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)
|
RNS.log("Client connected, but served path no longer exists!", RNS.LOG_ERROR)
|
||||||
link.teardown()
|
link.teardown()
|
||||||
|
|
||||||
|
def client_disconnected(link):
|
||||||
|
RNS.log("Client disconnected")
|
||||||
|
|
||||||
def client_request(message, packet):
|
def client_request(message, packet):
|
||||||
global serve_path
|
global serve_path
|
||||||
if message in list_files():
|
if message in list_files():
|
||||||
@ -235,7 +240,7 @@ def download(filename):
|
|||||||
# to select which files to download, or quit
|
# to select which files to download, or quit
|
||||||
menu_mode = None
|
menu_mode = None
|
||||||
def menu():
|
def menu():
|
||||||
global server_files
|
global server_files, server_link
|
||||||
# Wait until we have a filelist
|
# Wait until we have a filelist
|
||||||
while len(server_files) == 0:
|
while len(server_files) == 0:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
@ -266,6 +271,9 @@ def menu():
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if should_quit:
|
||||||
|
server_link.teardown()
|
||||||
|
|
||||||
# Prints out menus or screens for the
|
# Prints out menus or screens for the
|
||||||
# various states of the client program.
|
# various states of the client program.
|
||||||
# It's simple and quite uninteresting.
|
# 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")
|
RNS.log("The link was closed by the server, exiting now")
|
||||||
else:
|
else:
|
||||||
RNS.log("Link closed, exiting now")
|
RNS.log("Link closed, exiting now")
|
||||||
|
|
||||||
|
time.sleep(1.5)
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
|
|
||||||
# When RNS detects that the download has
|
# When RNS detects that the download has
|
||||||
|
Loading…
Reference in New Issue
Block a user