Closed logankuzyk closed 4 years ago
nnections.cleanup
Good eye finding that bug, those things can be difficult to diagnose! Next meeting I am just going to get you to go over how you are testing the module, I will get it running on my machine then we can get everything merged up!
I implemented a new technique to listen for new connections which prevents race conditions and thread blocking.
There was an error in the
connections.add()
method, which set the initial connection time as 0 instead oftime.time()
. This caused all connections to be removed every timeconnections.cleanup()
got called, because the expression for the delta would simplify totime.time() - 0
. There were also issues with disconnecting and reconnecting to the video server due to my incorrect usage of locks.Main and listen are still the only two threads in the program. The
listen()
method got changed the most. Instead of being constantly blocked bysocket.recvfrom()
and sleeping, I usedsocket.timeout
and an exception handler to prevent the thread from blockingbroadcast()
when updating connections.With this new design,
listen()
can continuously loop with only one thread. This allows for the periodic execution ofconnections.cleanup()
and avoiding down time while listening by not using sleep (connections would be rejected if they tried to connect when listen was sleeping).