From 1e974a74d61d5276374b50ffd793524955f87cf6 Mon Sep 17 00:00:00 2001 From: informaniac Date: Fri, 1 Dec 2017 18:11:42 +0100 Subject: [PATCH] moved creation of the socket into main function --- games/ttrs.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/games/ttrs.py b/games/ttrs.py index 51ee92b..a816156 100755 --- a/games/ttrs.py +++ b/games/ttrs.py @@ -243,13 +243,7 @@ class BalanceTtrsPlayer(TtrsPlayer, threading.Thread): self.start() def run(self): - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - try: - sock.connect(self.addr) - except ConnectionRefusedError: - print('could not connect to balance server', file=sys.stderr) - self.evt = PlayerEvent.QUIT - return + self.running = True evt = None oldevt = None @@ -481,6 +475,14 @@ if __name__ == '__main__': seed = random.random() games = [] + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + host, port = args.balance.split(':') + try: + sock.connect(host, port) + except ConnectionRefusedError: + print('could not connect to balance server', file=sys.stderr) + sys.exit(1) + def start_game(player_id, xpos): pg = Playground(10, 16) if args.pygame: