Clean the main-loop from useless instructions

Remove:
 - try/catch for received case, seems to be useless
 - useless `continue`
 - **move closing connection at the script's end** from TODO, do not find how to exit while from handler()
This commit is contained in:
Fred Z 2018-03-01 10:56:35 +01:00
parent 86b0b983f7
commit 3c5c169045
2 changed files with 7 additions and 18 deletions

View File

@ -8,8 +8,8 @@
- [x] ~~crash after 2 <ctrl+c> in client~~
- [x] ~~sending welcome message only at 1st client connection FIX #20~~
- [x] ~~client freeze when sending empty string or spaces~~
- [x] ~~move closing connection at the script's end~~
- [ ] asking/using client-nickname
- [ ] clean the prompt and std.out a bit messy since broadcasting
- [ ] move closing connection at the script's end
- [ ] using wlist with select.select for hardening the script
- [ ] …

View File

@ -71,24 +71,13 @@ while 1:
socket_object.send(MSG_WELCOME)
else: # receiving data
try:
data = socket.recv(BUFFER).decode().strip()
if data.upper() == "QUIT":
print(MSG_CLIENT_DISCONNECTED.format(socket.getpeername()))
broadcast(socket, MSG_DISCONNECTED)
inputs.remove(socket)
socket.close()
continue
elif data:
print(MSG_CLIENT_ID.format(socket.getpeername(), data))
broadcast(socket, data)
except Exception as except_detail:
print("Exception: «{}»".format(except_detail))
data = socket.recv(BUFFER).decode().strip()
if data.upper() == "QUIT":
print(MSG_CLIENT_DISCONNECTED.format(socket.getpeername()))
import pdb; pdb.set_trace()
broadcast(socket, MSG_DISCONNECTED)
inputs.remove(socket)
socket.close()
continue
MAIN_CONNECTION.close()
elif data:
print(MSG_CLIENT_ID.format(socket.getpeername(), data))
broadcast(socket, data)