Display welcome message when a client connects #20

FIX #20 sending welcome message only at 1st client connection
This commit is contained in:
Fred Z 2018-02-28 14:26:13 +01:00
parent c863a2c727
commit 594fa78141
2 changed files with 3 additions and 3 deletions

View File

@ -6,7 +6,7 @@
- [x] ~~broadcasting messages to all client connected~~
- [x] ~~show message on server when client use <ctrl+c>~~
- [x] ~~crash after 2 <ctrl+c> in client~~
- [ ] sending welcome message only at 1st client connection
- [x] ~~sending welcome message only at 1st client connection FIX #20~~
- [ ] asking/using client-nickname
- [ ] client freeze when sending empty string or spaces
- [ ] clean the prompt and std.out a bit messy since broadcasting

View File

@ -65,7 +65,8 @@ while 1:
socket_object, socket_addr = socket.accept()
inputs.append(socket_object)
print(MSG_NEW_CLIENT.format(socket_addr))
broadcast(socket, MSG_NEW_CLIENT.format(socket_addr))
broadcast(socket_object, MSG_NEW_CLIENT.format(socket_addr))
socket_object.send(MSG_WELCOME)
else: # receiving data
try:
@ -81,7 +82,6 @@ while 1:
elif data:
print(MSG_CLIENT_ID.format(socket.getpeername(), data))
broadcast(socket, data)
socket.send(MSG_WELCOME)
except Exception as except_detail:
print("Exception: «{}»".format(except_detail))
print(MSG_CLIENT_DISCONNECTED.format(socket.getpeername()))