Выполнено задание 2

This commit is contained in:
ChebykinAS 2026-05-04 21:18:54 +03:00
parent 8f60c73d7c
commit b0d03fa66a
10 changed files with 69 additions and 0 deletions

2
.gitignore vendored
View File

@ -0,0 +1,2 @@
venv/
config.py

View File

@ -0,0 +1 @@
# Практика: Сетевые соединения в Python

Binary file not shown.

7
gitea_read.py Normal file
View File

@ -0,0 +1,7 @@
import requests
from config import TOKEN
headers = {"Authorization": f"token {TOKEN}"}
response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers)
print(response.json())

4
http_requests.py Normal file
View File

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

9
http_socket.py Normal file
View File

@ -0,0 +1,9 @@
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('vyatsu.ru', 80))
request = "GET / HTTP/1.1\r\nHost: vyatsu.ru\r\n\r\n"
client.sendall(request.encode())
response = client.recv(4096)
print(response.decode())
client.close()

8
tcp_client.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'EXIT')
data = client.recv(1024)
print(f"Ответ от сервера: {data.decode()}")
client.close()

21
tcp_server.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_client.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', 10005))
data, _ = client.recvfrom(1024)
print(f"Ответ от сервера: {data.decode()}")
client.close()

10
udp_server.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', 10005))
print("UDP сервер запущен")
while True:
data, addr = server.recvfrom(1024)
print(f"Сообщение от {addr}: {data.decode()}")
server.sendto(b"MODIFIED: " + data, addr)