From 93038531b8840e6c123f8957a2a7bdb2b3e056a3 Mon Sep 17 00:00:00 2001 From: Fernando Erd <fce15@inf.ufpr.br> Date: Thu, 3 Nov 2016 22:52:49 -0200 Subject: [PATCH] Fix Error thread --- Canguru/CanguruChat.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/Canguru/CanguruChat.py b/Canguru/CanguruChat.py index 1312425..8859fb0 100755 --- a/Canguru/CanguruChat.py +++ b/Canguru/CanguruChat.py @@ -31,9 +31,9 @@ import threading import sys import binascii +MACHINE_ID = 1 SEND_PORT = 5000 # Porta que o Servidor envia RECV_PORT = 5000 # Porta que o Servidor recebe -MACHINE_ID = 1 class Protocol(): def __init__ (self): @@ -98,18 +98,10 @@ class Protocol(): return "%08X" % buff def client (): - udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - dest = (HOST, SEND_PORT) - print 'Para sair digite exit\n' - protocolMessage = Protocol() - protocolMessage.setDestiny() - protocolMessage.setPriority() - protocolMessage.setMessage() - protocolMessage.setSizeof() - protocolMessage.setCRC32() - msg = protocolMessage.getEmpacotar() - while protocolMessage.msg <> 'exit': - udp.sendto (msg, dest) + try: + udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + dest = (HOST, SEND_PORT) + print 'Para sair digite exit\n' protocolMessage = Protocol() protocolMessage.setDestiny() protocolMessage.setPriority() @@ -117,8 +109,20 @@ def client (): protocolMessage.setSizeof() protocolMessage.setCRC32() msg = protocolMessage.getEmpacotar() - threadServer._Thread__stop() - udp.close() + while protocolMessage.msg <> 'exit': + udp.sendto (msg, dest) + protocolMessage = Protocol() + protocolMessage.setDestiny() + protocolMessage.setPriority() + protocolMessage.setMessage() + protocolMessage.setSizeof() + protocolMessage.setCRC32() + msg = protocolMessage.getEmpacotar() + threadServer._Thread__stop() + udp.close() + except: + print 'OPS, ALGO OCORREU ERRADO' + threadServer._Thread__stop() def server (): udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) -- GitLab