@server,clients简单实例

服务端:
import socket
import time
socket = socket.socket()
ip = socket.bind(('192.168.15.85',8000))
socket.listen(5)
conn,add = socket.accept()#阻塞等待

# while True:
# s = conn.recv(1024) # 接受bytes类型
# t = s.decode('utf-8') #转换成字符串
# dd = time.localtime(float(t))
# td = time.strftime("%Y/%m/%d %H:%M:%S",dd)
# print(td)

# # input('请输入聊天文字:')
# s='发送'
# # conn.send(s.encode('utf-8'))
# socket.close()


#
# while True:
# s = conn.recv(1024)
# t = s.decode('utf-8')
# print('收到:%s' % t)
# ss = input('输入框:')
# ts =conn.send(ss.encode('utf-8'))


客户端:
import socket
import time
socket = socket.socket()
ip = ('192.168.15.85',8000)

socket.connect(ip)

# while True:
# time.sleep(2)
# s= time.time()
# socket.send(str(s).encode('utf-8'))
# #
# # t = socket.recv(1024)#阻塞住 等待接受
# # ts = t.decode('utf-8')
# # print(ts)
# socket.close()



# while True:
# s = input('输入框:')
# socket.send(s.encode('utf-8'))
# o = socket.recv(1024)
# oo = o.decode('utf-8')
# print('收到:%s'% oo)



原文地址:https://www.cnblogs.com/li-123-peng/p/9794951.html