arcs

Amateur Radio Chat Server with a modern interface
git clone git://squid-tech.com/arcs.git
Log | Files | Refs | README

commit ecf77db184fdc7da1700231b17e5526e9af24081
parent 42ceaf90db68d24ecc74c9e1427445d373847c47
Author: joshiemoore <jxm5210@g.rit.edu>
Date:   Fri, 20 Dec 2019 03:03:50 -0500

Add keep-alive daemon to prevent clients from disconnecting

Diffstat:
Marcs.py | 33+++++++++++++++++++++++----------
1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/arcs.py b/arcs.py @@ -42,6 +42,16 @@ TIMEOUT = 300 +### client config ### + +# how long to delay between sending automatic /pings +# don't set this too low - there's no reason to +ALIVED_DELAY = 240 + +##################### + + + KISS_FEND = 0xC0 KISS_FESC = 0xDB KISS_TFEND = 0xDC @@ -57,7 +67,7 @@ _SERVER = False _USERS = {} -_PATH = ["KD2AYD-3"] +_PATH = ["WIDE2-2"] """ @@ -235,7 +245,6 @@ def relay(port, msg): Respond to /commands sent by users. """ def handleCommand(port, user, command): - print(user) if ("/ping" in command): # keep the user alive _USERS[user] = (int(time.time()), command) @@ -320,6 +329,15 @@ def clientd(port, textdisplay): textdisplay.insert("end", dispmsg) +""" +Automatically keep the client alive by periodically sending /ping commands +to the server. +""" +def alived(port): + while True: + time.sleep(ALIVED_DELAY) + sendMessage(port, MYCALL, HOST, _PATH, "/ping") + """ Send a chat message from the GUI, and clear the text box. @@ -328,12 +346,6 @@ def chatGuiSend(port, entryText): sendMessage(port, MYCALL, HOST, _PATH, entryText.get()) entryText.set("") - -def testing(port): - while True: - time.sleep(10) - sendMessage(port, MYCALL + "-" + str(random.randint(2, 5)), HOST, _PATH, "/ping -r") - def main(): global _SERVER @@ -384,12 +396,13 @@ def main(): # start server daemon threading.Thread(target=serverd, args=[ser, display]).start() - - threading.Thread(target=testing, args=[ser]).start() else: # start client daemon threading.Thread(target=clientd, args=[ser, display]).start() + # start keep-alive daemon + threading.Thread(target=alived, args=[ser]).start() + # start the GUI top.mainloop()