-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat_client.py
44 lines (30 loc) · 955 Bytes
/
chat_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from sys import argv
from pynet import Client
class ChatClient(Client):
def __init__(self, socket, name):
self.socket = socket
self.name = name
self.msg = ""
self.old_database = {}
def on_send(self):
return {self.name: self.msg}
def on_recv(self, database):
for user in database:
if user == self.name:
continue
if user in self.old_database and database[user] != self.old_database[user]:
print(user, ":", database[user])
self.old_database = database
def send_msg(self, msg):
self.msg = msg
def main():
c = ChatClient.from_address((argv[1], argv[2]), input("name: "))
c.start()
try:
while True:
msg = input("")
c.send_msg(msg)
except KeyboardInterrupt:
print("Exited")
if __name__ == "__main__":
main()