Python_服务器与多客户端通信、UDP协议、pycharm打印带颜色输出、时间同步的机制

1、服务器与多客户端通信

 1 import socket
 2 # 创建tcp socket的套接字
 3 sk = socket.socket()
 4 # bind
 5 sk.bind(('127.0.0.1',8080))
 6 # 监听
 7 sk.listen(5)
 8 # 等待连接
 9 while 1:
10     conn, addr = sk.accept()
11     while 1:
12         msg_s = input('>>>')
13         conn.send(msg_s.encode('utf-8'))
14         if msg_s == 'q':
15             break
16         msg_r = conn.recv(1024).decode('utf-8')
17         if msg_r == 'q':
18             break
19         print(msg_r)
20     conn.close()
21 
22 sk.close()
TCP_服务器端

 

 1 import socket
 2 
 3 sk = socket.socket()
 4 
 5 sk.connect(('127.0.0.1',8080))
 6 
 7 
 8 while 1:
 9     msg_r = sk.recv(1024).decode('utf-8')
10     if msg_r == 'q':
11         break
12     print(msg_r)
13     msg_s = input('>>>')
14     sk.send(msg_s.encode('utf-8'))
15     if msg_s == 'q':
16         break
17 
18 sk.close()
TCP_客户端

 

2、UDP协议

   未完待续

 

3、pycharm打印带颜色输出

 未完待续

 

4、时间同步的机制

 未完待续

 

posted @ 2018-06-05 22:00  AKA绒滑服贵  阅读(223)  评论(0编辑  收藏  举报