Python-100-Days/Day01-15/code/Day14/socket4.py

21 lines
444 B
Python
Raw Normal View History

2018-04-27 00:00:22 +08:00
"""
套接字 - 基于UDP协议创建Echo客户端
Version: 0.1
Author: 骆昊
Date: 2018-03-22
"""
from socket import *
client = socket(AF_INET, SOCK_DGRAM)
while True:
2019-05-03 21:17:36 +08:00
data_str = input('请输入: ')
client.sendto(data_str.encode('utf-8'), ('localhost', 6789))
data, addr = client.recvfrom(1024)
data_str = data.decode('utf-8')
print('服务器回应:', data_str)
if data_str == 'bye':
break
2018-04-27 00:00:22 +08:00
client.close()