practice03-api-mamaev/udp_client.py

18 lines
489 B
Python

import socket
HOST = "127.0.0.1"
PORT = 10001
def main():
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while True:
msg = input("Введите сообщение (EXIT для выхода): ")
client.sendto(msg.encode(), (HOST, PORT))
data, _ = client.recvfrom(1024)
print(f"Ответ от сервера: {data.decode()}")
if msg.upper() == "EXIT":
break
client.close()
if __name__ == "__main__":
main()