3 практика сделана

This commit is contained in:
Дарья Растегаева 2025-05-15 12:34:44 +03:00
parent 709925ebf3
commit 5260aee6b0
8 changed files with 78 additions and 1 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
venv
.env

8
TCP-клиент.py Normal file
View File

@ -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()

21
TCP-сервер.py Normal file
View File

@ -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

7
UDP-клиент.py Normal file
View File

@ -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()

10
UDP-сервер.py Normal file
View File

@ -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)

4
tcp.py Normal file
View File

@ -0,0 +1,4 @@
import requests
response = requests.get("http://vyatsu.ru")
print(response.text[:500])

10
tocen.py Normal file
View File

@ -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())

16
tocenread.py Normal file
View File

@ -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())