/
ilya.petrash
/
SimplePyScripts
Обзор
Документация
Войти
/
ilya.petrash
/
SimplePyScripts
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
socket__tcp__examples/send_recv_json/client.py
37 строк
622 B
gil9red
Refactoring. Using f-strings
26 июн 2023, 16:21
26 июн 2023, 16:21
b6816f4
Код
Авторство
О чём код?
#!/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = "ipetrash" import json import socket import sys sys.path.append("..") from common import send_msg, recv_msg HOST, PORT = "localhost", 9090 with socket.socket() as sock: sock.connect((HOST, PORT)) data = { "title": "test", "counter": 1, } data = json.dumps(data) data = bytes(data, "utf-8") print(f"Sending ({len(data)}): {data}") print() send_msg(sock, data) print("Receiving") response_data = recv_msg(sock) print(f"Response ({len(response_data)}): {response_data}") print("Close\n")