Skip to content

Commit

Permalink
fix: broadcast the msg to all clients not the server
Browse files Browse the repository at this point in the history
  • Loading branch information
chefZau committed Oct 21, 2021
1 parent 121f5e5 commit 610726c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def broadcast(clientName, message):
"""
for name, conn in clients.items():
formatedMessage = f'@{clientName}: {message}'
if name != clientName:
if clientName == '':
conn.sendall(message.encode(FORMAT))
elif name != clientName:
conn.sendall(formatedMessage.encode(FORMAT))


Expand Down Expand Up @@ -140,7 +142,10 @@ def main():
def signalHandler(sig, frame):
"""Executed when a user press control + c"""
print('Interrupt received, shutting down ...')
server.sendall('DISCONNECT CHAT/1.0'.encode(FORMAT))

disconnectMsg = 'DISCONNECT CHAT/1.0'
broadcast('', disconnectMsg)

server.close()
sys.exit(0)

Expand Down

0 comments on commit 610726c

Please sign in to comment.