Выполнено задание 2
This commit is contained in:
parent
8f60c73d7c
commit
b0d03fa66a
2
.gitignore
vendored
2
.gitignore
vendored
@ -0,0 +1,2 @@
|
|||||||
|
venv/
|
||||||
|
config.py
|
||||||
BIN
__pycache__/config.cpython-314.pyc
Normal file
BIN
__pycache__/config.cpython-314.pyc
Normal file
Binary file not shown.
7
gitea_read.py
Normal file
7
gitea_read.py
Normal 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
4
http_requests.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
response = requests.get("http://vyatsu.ru")
|
||||||
|
print(response.text[:500])
|
||||||
9
http_socket.py
Normal file
9
http_socket.py
Normal 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
8
tcp_client.py
Normal 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
21
tcp_server.py
Normal 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
7
udp_client.py
Normal 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
10
udp_server.py
Normal 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)
|
||||||
Loading…
Reference in New Issue
Block a user