forked from l121503258/xuexi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathce1.py
37 lines (36 loc) · 905 Bytes
/
ce1.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
"""
@author: lileilei
@file: ce1.py
@time: 2018/5/21 9:23
"""
import socket,threading
host='127.0.0.1'
port=999
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
def sendmessage():
while True:
input_data = input('请输入:')
s.sendall(input_data.encode(encoding='utf-8'))
def recvmessage():
while True:
data=s.recv(1024)
if data=='':
data=s.recv(1024)
elif data=='quit':
s.close()
else:
print(data.decode('utf-8'))
if __name__=='__main__':
thss=[]
beijing=''
th1=threading.Thread(target=sendmessage,args=())
th2=threading.Thread(target=recvmessage,args=())
thss.append(th1)
thss.append(th2)
for i in range(len(thss)):
thss[i].start()
thss[0].join()
# th1.start()
# th2.start()
# th1.join()