diff --git a/Examples/Announce.py b/Examples/Announce.py index 69c94cb..c50fb25 100644 --- a/Examples/Announce.py +++ b/Examples/Announce.py @@ -6,6 +6,7 @@ import argparse import random +import sys import RNS # Let's define an app name. We'll use this for all @@ -168,4 +169,4 @@ if __name__ == "__main__": except KeyboardInterrupt: print("") - exit() \ No newline at end of file + sys.exit(0) \ No newline at end of file diff --git a/Examples/Broadcast.py b/Examples/Broadcast.py index 76acc70..e2f26f5 100644 --- a/Examples/Broadcast.py +++ b/Examples/Broadcast.py @@ -118,4 +118,4 @@ if __name__ == "__main__": except KeyboardInterrupt: print("") - exit() \ No newline at end of file + sys.exit(0) \ No newline at end of file diff --git a/Examples/Buffer.py b/Examples/Buffer.py index 6805184..0c39d49 100644 --- a/Examples/Buffer.py +++ b/Examples/Buffer.py @@ -157,7 +157,7 @@ def client(destination_hexhash, configpath): destination_hash = bytes.fromhex(destination_hexhash) except: RNS.log("Invalid destination entered. Check your input!\n") - exit() + sys.exit(0) # We must first initialise Reticulum reticulum = RNS.Reticulum(configpath) @@ -254,9 +254,8 @@ def link_closed(link): else: RNS.log("Link closed, exiting now") - RNS.Reticulum.exit_handler() time.sleep(1.5) - os._exit(0) + sys.exit(0) # When the buffer has new data, read it and write it to the terminal. def client_buffer_ready(ready_bytes: int): @@ -320,4 +319,4 @@ if __name__ == "__main__": except KeyboardInterrupt: print("") - exit() \ No newline at end of file + sys.exit(0) \ No newline at end of file diff --git a/Examples/Channel.py b/Examples/Channel.py index c4ce315..17fe78b 100644 --- a/Examples/Channel.py +++ b/Examples/Channel.py @@ -124,7 +124,7 @@ def server(configpath): def server_loop(destination): # Let the user know that everything is ready RNS.log( - "Link example "+ + "Channel example "+ RNS.prettyhexrep(destination.hash)+ " running, waiting for a connection." ) @@ -212,7 +212,7 @@ def client(destination_hexhash, configpath): destination_hash = bytes.fromhex(destination_hexhash) except: RNS.log("Invalid destination entered. Check your input!\n") - exit() + sys.exit(0) # We must first initialise Reticulum reticulum = RNS.Reticulum(configpath) @@ -276,7 +276,7 @@ def client_loop(): packed_size = len(message.pack()) channel = server_link.get_channel() if channel.is_ready_to_send(): - if packed_size <= channel.MDU: + if packed_size <= channel.mdu: channel.send(message) else: RNS.log( @@ -321,9 +321,8 @@ def link_closed(link): else: RNS.log("Link closed, exiting now") - RNS.Reticulum.exit_handler() time.sleep(1.5) - os._exit(0) + sys.exit(0) # When a packet is received over the channel, we # simply print out the data. @@ -387,4 +386,4 @@ if __name__ == "__main__": except KeyboardInterrupt: print("") - exit() \ No newline at end of file + sys.exit(0) \ No newline at end of file diff --git a/Examples/Echo.py b/Examples/Echo.py index e5b3930..b27e303 100644 --- a/Examples/Echo.py +++ b/Examples/Echo.py @@ -6,6 +6,7 @@ ########################################################## import argparse +import sys import RNS # Let's define an app name. We'll use this for all @@ -130,7 +131,7 @@ def client(destination_hexhash, configpath, timeout=None): except Exception as e: RNS.log("Invalid destination entered. Check your input!") RNS.log(str(e)+"\n") - exit() + sys.exit(0) # We must first initialise Reticulum reticulum = RNS.Reticulum(configpath) @@ -328,4 +329,4 @@ if __name__ == "__main__": client(args.destination, configarg, timeout=timeoutarg) except KeyboardInterrupt: print("") - exit() \ No newline at end of file + sys.exit(0) \ No newline at end of file diff --git a/Examples/Filetransfer.py b/Examples/Filetransfer.py index 98c4c7a..65fceaf 100644 --- a/Examples/Filetransfer.py +++ b/Examples/Filetransfer.py @@ -224,7 +224,7 @@ def client(destination_hexhash, configpath): destination_hash = bytes.fromhex(destination_hexhash) except: RNS.log("Invalid destination entered. Check your input!\n") - exit() + sys.exit(0) # We must first initialise Reticulum reticulum = RNS.Reticulum(configpath) @@ -462,7 +462,7 @@ def filelist_timeout_job(): global server_files if len(server_files) == 0: RNS.log("Timed out waiting for filelist, exiting") - os._exit(0) + sys.exit(0) # When a link is closed, we'll inform the @@ -475,9 +475,8 @@ def link_closed(link): else: RNS.log("Link closed, exiting now") - RNS.Reticulum.exit_handler() time.sleep(1.5) - os._exit(0) + sys.exit(0) # When RNS detects that the download has # started, we'll update our menu state @@ -601,4 +600,4 @@ if __name__ == "__main__": except KeyboardInterrupt: print("") - exit() \ No newline at end of file + sys.exit(0) \ No newline at end of file diff --git a/Examples/Identify.py b/Examples/Identify.py index 45ba18e..ec7af53 100644 --- a/Examples/Identify.py +++ b/Examples/Identify.py @@ -133,7 +133,7 @@ def client(destination_hexhash, configpath): destination_hash = bytes.fromhex(destination_hexhash) except: RNS.log("Invalid destination entered. Check your input!\n") - exit() + sys.exit(0) # We must first initialise Reticulum reticulum = RNS.Reticulum(configpath) @@ -245,9 +245,8 @@ def link_closed(link): else: RNS.log("Link closed, exiting now") - RNS.Reticulum.exit_handler() time.sleep(1.5) - os._exit(0) + sys.exit(0) # When a packet is received over the link, we # simply print out the data. @@ -311,4 +310,4 @@ if __name__ == "__main__": except KeyboardInterrupt: print("") - exit() \ No newline at end of file + sys.exit(0) \ No newline at end of file diff --git a/Examples/Link.py b/Examples/Link.py index 6b3210c..b246307 100644 --- a/Examples/Link.py +++ b/Examples/Link.py @@ -119,7 +119,7 @@ def client(destination_hexhash, configpath): destination_hash = bytes.fromhex(destination_hexhash) except: RNS.log("Invalid destination entered. Check your input!\n") - exit() + sys.exit(0) # We must first initialise Reticulum reticulum = RNS.Reticulum(configpath) @@ -222,9 +222,8 @@ def link_closed(link): else: RNS.log("Link closed, exiting now") - RNS.Reticulum.exit_handler() time.sleep(1.5) - os._exit(0) + sys.exit(0) # When a packet is received over the link, we # simply print out the data. @@ -288,4 +287,4 @@ if __name__ == "__main__": except KeyboardInterrupt: print("") - exit() \ No newline at end of file + sys.exit(0) \ No newline at end of file diff --git a/Examples/Minimal.py b/Examples/Minimal.py index 76f78c6..0787233 100644 --- a/Examples/Minimal.py +++ b/Examples/Minimal.py @@ -5,6 +5,7 @@ ########################################################## import argparse +import sys import RNS # Let's define an app name. We'll use this for all @@ -98,4 +99,4 @@ if __name__ == "__main__": except KeyboardInterrupt: print("") - exit() \ No newline at end of file + sys.exit(0) \ No newline at end of file diff --git a/Examples/Ratchets.py b/Examples/Ratchets.py index e62ac17..aa2969d 100644 --- a/Examples/Ratchets.py +++ b/Examples/Ratchets.py @@ -5,6 +5,7 @@ ########################################################## import argparse +import sys import RNS # Let's define an app name. We'll use this for all @@ -138,7 +139,7 @@ def client(destination_hexhash, configpath, timeout=None): except Exception as e: RNS.log("Invalid destination entered. Check your input!") RNS.log(str(e)+"\n") - exit() + sys.exit(0) # We must first initialise Reticulum reticulum = RNS.Reticulum(configpath) @@ -337,4 +338,4 @@ if __name__ == "__main__": client(args.destination, configarg, timeout=timeoutarg) except KeyboardInterrupt: print("") - exit() \ No newline at end of file + sys.exit(0) \ No newline at end of file diff --git a/Examples/Request.py b/Examples/Request.py index ca8a993..7a56d72 100644 --- a/Examples/Request.py +++ b/Examples/Request.py @@ -119,7 +119,7 @@ def client(destination_hexhash, configpath): destination_hash = bytes.fromhex(destination_hexhash) except: RNS.log("Invalid destination entered. Check your input!\n") - exit() + sys.exit(0) # We must first initialise Reticulum reticulum = RNS.Reticulum(configpath) @@ -226,9 +226,8 @@ def link_closed(link): else: RNS.log("Link closed, exiting now") - RNS.Reticulum.exit_handler() time.sleep(1.5) - os._exit(0) + sys.exit(0) ########################################################## @@ -284,4 +283,4 @@ if __name__ == "__main__": except KeyboardInterrupt: print("") - exit() \ No newline at end of file + sys.exit(0) \ No newline at end of file diff --git a/Examples/Speedtest.py b/Examples/Speedtest.py index 5836262..755d5f9 100644 --- a/Examples/Speedtest.py +++ b/Examples/Speedtest.py @@ -149,8 +149,6 @@ def server_packet_received(message, packet): time.sleep(0.2) rc = 0 received_data = 0 - # latest_client_link.teardown() - # os._exit(0) ########################################################## @@ -159,6 +157,7 @@ def server_packet_received(message, packet): # A reference to the server link server_link = None +should_quit = False # This initialisation is executed when the users chooses # to run as a client @@ -175,7 +174,7 @@ def client(destination_hexhash, configpath): destination_hash = bytes.fromhex(destination_hexhash) except: RNS.log("Invalid destination entered. Check your input!\n") - exit() + sys.exit(0) # We must first initialise Reticulum reticulum = RNS.Reticulum(configpath) @@ -216,7 +215,7 @@ def client(destination_hexhash, configpath): client_loop() def client_loop(): - global server_link + global server_link, should_quit # Wait for the link to become active while not server_link: @@ -224,16 +223,7 @@ def client_loop(): should_quit = False while not should_quit: - try: - text = input() - - # Check if we should quit the example - if text == "quit" or text == "q" or text == "exit": - should_quit = True - server_link.teardown() - - except Exception as e: - raise e + time.sleep(0.2) # This function is called when a link # has been established with the server @@ -276,17 +266,17 @@ def link_established(link): # When a link is closed, we'll inform the # user, and exit the program def link_closed(link): + global should_quit if link.teardown_reason == RNS.Link.TIMEOUT: RNS.log("The link timed out, exiting now") elif link.teardown_reason == RNS.Link.DESTINATION_CLOSED: RNS.log("The link was closed by the server, exiting now") else: RNS.log("Link closed, exiting now") - - RNS.Reticulum.exit_handler() + should_quit = True time.sleep(1.5) - os._exit(0) + sys.exit(0) def client_packet_received(message, packet): pass @@ -344,4 +334,4 @@ if __name__ == "__main__": except KeyboardInterrupt: print("") - exit() + sys.exit(0)