Commits

Cédric Bonhomme  committed 93d9f14 Draft

Client Python leaves now the chat properly.

  • Participants
  • Parent commits 67b3485

Comments (0)

Files changed (1)

         """
         Receive messages.
         """
+        data = ""
         while True:
-            data = self.sock.recv(1024)
+            try:
+                data = self.sock.recv(1024)
+            except socket.error as e:
+                return
             if data:
                 print(data.decode("utf-8"))
 
         Send messages.
         """
         message = input("Please give yourname: ")
-        while True:
+        while message.strip() != "Q":
             self.sock.send(message.encode("utf-8"))
             message = input("you> ")
+        self.sock.shutdown(socket.SHUT_RDWR)
         self.sock.close()
 
 if __name__ == '__main__':