forked from jackfrued/Python-100-Days
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatclient.py
34 lines (26 loc) · 847 Bytes
/
chatclient.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
from socket import socket
from threading import Thread
def main():
class RefreshScreenThread(Thread):
def __init__(self, client):
super().__init__()
self._client = client
def run(self):
while running:
data = self._client.recv(1024)
print(data.decode('utf-8'))
nickname = input('请输入你的昵称: ')
myclient = socket()
myclient.connect(('10.7.189.118', 12345))
running = True
RefreshScreenThread(myclient).start()
while running:
content = input('请发言: ')
if content == 'byebye':
myclient.send(content.encode('utf-8'))
running = False
else:
msg = nickname + ': ' + content
myclient.send(msg.encode('utf-8'))
if __name__ == '__main__':
main()