From 5260aee6b024de87788f63835acba344d957126c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D1=88=D0=B0=20=D0=A0=D0=B0=D1=81=D1=82=D0=B5?= =?UTF-8?q?=D0=B3=D0=B0=D0=B5=D0=B2=D0=B0?= Date: Thu, 15 May 2025 12:34:44 +0300 Subject: [PATCH] =?UTF-8?q?3=20=D0=BF=D1=80=D0=B0=D0=BA=D1=82=D0=B8=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- TCP-клиент.py | 8 ++++++++ TCP-сервер.py | 21 +++++++++++++++++++++ UDP-клиент.py | 7 +++++++ UDP-сервер.py | 10 ++++++++++ tcp.py | 4 ++++ tocen.py | 10 ++++++++++ tocenread.py | 16 ++++++++++++++++ 8 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 TCP-клиент.py create mode 100644 TCP-сервер.py create mode 100644 UDP-клиент.py create mode 100644 UDP-сервер.py create mode 100644 tcp.py create mode 100644 tocen.py create mode 100644 tocenread.py diff --git a/.gitignore b/.gitignore index f5e96db..2d19ec7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -venv \ No newline at end of file +venv +.env \ No newline at end of file diff --git a/TCP-клиент.py b/TCP-клиент.py new file mode 100644 index 0000000..531b2ce --- /dev/null +++ b/TCP-клиент.py @@ -0,0 +1,8 @@ +import socket + +client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +client.connect(('127.0.0.1', 10000)) +client.sendall(b'hello server') +data = client.recv(1024) +print(f"Ответ от сервера: {data.decode()}") +client.close() \ No newline at end of file diff --git a/TCP-сервер.py b/TCP-сервер.py new file mode 100644 index 0000000..8f14be6 --- /dev/null +++ b/TCP-сервер.py @@ -0,0 +1,21 @@ +import socket + +server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +server.bind(("0.0.0.0", 10000)) +server.listen(1) +print("TCP сервер запущен") + +while True: + + conn, addr = server.accept() + print(f"Подключение от {addr}") + + data = conn.recv(1024) + if not data: + break + conn.sendall(data.upper()) + + conn.close() + + if data.upper() == b'EXIT': + break \ No newline at end of file diff --git a/UDP-клиент.py b/UDP-клиент.py new file mode 100644 index 0000000..7b18107 --- /dev/null +++ b/UDP-клиент.py @@ -0,0 +1,7 @@ +import socket + +client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +client.sendto(b'hello server', ('127.0.0.1', 8000)) +data, _ = client.recvfrom(1024) +print(f"Ответ от сервера: {data.decode()}") +client.close() \ No newline at end of file diff --git a/UDP-сервер.py b/UDP-сервер.py new file mode 100644 index 0000000..eaf00cb --- /dev/null +++ b/UDP-сервер.py @@ -0,0 +1,10 @@ +import socket + +server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +server.bind(('0.0.0.0', 8000)) +print("UDP сервер запущен") + +while True: + data, addr = server.recvfrom(1024) + print(f"Сообщение от {addr}: {data.decode()}") + server.sendto(data.upper(), addr) \ No newline at end of file diff --git a/tcp.py b/tcp.py new file mode 100644 index 0000000..83588ae --- /dev/null +++ b/tcp.py @@ -0,0 +1,4 @@ +import requests + +response = requests.get("http://vyatsu.ru") +print(response.text[:500]) \ No newline at end of file diff --git a/tocen.py b/tocen.py new file mode 100644 index 0000000..8b71f39 --- /dev/null +++ b/tocen.py @@ -0,0 +1,10 @@ +import os +from dotenv import load_dotenv +import requests + +load_dotenv() + +TOKEN = os.getenv("GITEA_TOKEN") +headers = {"Authorization": f"token {TOKEN}"} +response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers) +print(response.json()) \ No newline at end of file diff --git a/tocenread.py b/tocenread.py new file mode 100644 index 0000000..55332f4 --- /dev/null +++ b/tocenread.py @@ -0,0 +1,16 @@ +import requests +from dotenv import load_dotenv +import os + +load_dotenv() +TOKEN = os.getenv("GITEA_TOKENREAD") +headers = {"Authorization": f"token {TOKEN}"} + +data = { + "name": "Practica3RAST", + "private": False, + "description": "Создали репозиторий с помощью API" +} + +response = requests.post("https://git.vyatsu.ru/api/v1/user/repos", headers=headers, json=data) +print(response.json()) \ No newline at end of file