码迷,mamicode.com
首页 > 其他好文 > 详细

@server,clients简单实例

时间:2018-10-15 23:25:09      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:serve   转换   发送   byte   soc   cal   utf-8   cli   server   

服务端:
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)



@server,clients简单实例

标签:serve   转换   发送   byte   soc   cal   utf-8   cli   server   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!