@@ -149,8 +149,6 @@ def server_packet_received(message, packet):
149
149
time .sleep (0.2 )
150
150
rc = 0
151
151
received_data = 0
152
- # latest_client_link.teardown()
153
- # os._exit(0)
154
152
155
153
156
154
##########################################################
@@ -159,6 +157,7 @@ def server_packet_received(message, packet):
159
157
160
158
# A reference to the server link
161
159
server_link = None
160
+ should_quit = False
162
161
163
162
# This initialisation is executed when the users chooses
164
163
# to run as a client
@@ -175,7 +174,7 @@ def client(destination_hexhash, configpath):
175
174
destination_hash = bytes .fromhex (destination_hexhash )
176
175
except :
177
176
RNS .log ("Invalid destination entered. Check your input!\n " )
178
- exit ()
177
+ sys . exit (0 )
179
178
180
179
# We must first initialise Reticulum
181
180
reticulum = RNS .Reticulum (configpath )
@@ -216,24 +215,15 @@ def client(destination_hexhash, configpath):
216
215
client_loop ()
217
216
218
217
def client_loop ():
219
- global server_link
218
+ global server_link , should_quit
220
219
221
220
# Wait for the link to become active
222
221
while not server_link :
223
222
time .sleep (0.1 )
224
223
225
224
should_quit = False
226
225
while not should_quit :
227
- try :
228
- text = input ()
229
-
230
- # Check if we should quit the example
231
- if text == "quit" or text == "q" or text == "exit" :
232
- should_quit = True
233
- server_link .teardown ()
234
-
235
- except Exception as e :
236
- raise e
226
+ time .sleep (0.2 )
237
227
238
228
# This function is called when a link
239
229
# has been established with the server
@@ -276,17 +266,17 @@ def link_established(link):
276
266
# When a link is closed, we'll inform the
277
267
# user, and exit the program
278
268
def link_closed (link ):
269
+ global should_quit
279
270
if link .teardown_reason == RNS .Link .TIMEOUT :
280
271
RNS .log ("The link timed out, exiting now" )
281
272
elif link .teardown_reason == RNS .Link .DESTINATION_CLOSED :
282
273
RNS .log ("The link was closed by the server, exiting now" )
283
274
else :
284
275
RNS .log ("Link closed, exiting now" )
285
-
286
- RNS .Reticulum .exit_handler ()
287
276
277
+ should_quit = True
288
278
time .sleep (1.5 )
289
- os . _exit (0 )
279
+ sys . exit (0 )
290
280
291
281
def client_packet_received (message , packet ):
292
282
pass
@@ -344,4 +334,4 @@ def client_packet_received(message, packet):
344
334
345
335
except KeyboardInterrupt :
346
336
print ("" )
347
- exit ()
337
+ sys . exit (0 )
0 commit comments