CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day14/socket4.py
Views: 729
1
"""
2
套接字 - 基于UDP协议创建Echo客户端
3
4
Version: 0.1
5
Author: 骆昊
6
Date: 2018-03-22
7
"""
8
9
from socket import *
10
11
client = socket(AF_INET, SOCK_DGRAM)
12
while True:
13
data_str = input('请输入: ')
14
client.sendto(data_str.encode('utf-8'), ('localhost', 6789))
15
data, addr = client.recvfrom(1024)
16
data_str = data.decode('utf-8')
17
print('服务器回应:', data_str)
18
if data_str == 'bye':
19
break
20
client.close()
21
22