客户端代码:
import socket
import time
while True:
s = socket.socket()
addr=("127.0.0.1",9999)
print("{}:wait for server connect...".format(time.ctime()))
while True:
time.sleep(1)
try:
res=s.connect(addr)
print(res)
if not res:
print("connect server",addr)
break
except:
pass
while True:
try:
data=s.recv(1024).decode('utf-8')
if not data:
break
for data in [b'Michael', b'Tracy', b'Sarah']:
# 发送数据:
s.send(data)
print(s.recv(1024).decode('utf-8'))
bre