Загрузить файлы в «/»
This commit is contained in:
parent
e9d813b189
commit
ed53d9155e
4
request.py
Normal file
4
request.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
response = requests.get("http://vyatsu.ru")
|
||||||
|
print(response.text[:500])
|
24
socket_client.py
Normal file
24
socket_client.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import socket
|
||||||
|
import requests
|
||||||
|
|
||||||
|
# Используем requests для получения данных
|
||||||
|
response = requests.get('http://vyatsu.ru')
|
||||||
|
print("Ответ с использованием requests:")
|
||||||
|
print(response.text)
|
||||||
|
|
||||||
|
# Ручной запрос через сокет (TCP)
|
||||||
|
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
client.connect(('vyatsu.ru', 80))
|
||||||
|
request = "GET / HTTP/1.1\r\nHost: vyatsu.ru\r\nConnection: close\r\n\r\n"
|
||||||
|
client.sendall(request.encode())
|
||||||
|
response = b""
|
||||||
|
|
||||||
|
while True:
|
||||||
|
part = client.recv(4096)
|
||||||
|
if not part:
|
||||||
|
break
|
||||||
|
response += part
|
||||||
|
|
||||||
|
print("\nОтвет с использованием socket:")
|
||||||
|
print(response.decode())
|
||||||
|
client.close()
|
14
tcp_client1.py
Normal file
14
tcp_client1.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
server.bind(('0.0.0.0', 10011))
|
||||||
|
print("UDP сервер запущен на порту 11011")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
data, addr = server.recvfrom(1024)
|
||||||
|
message = data.decode()
|
||||||
|
print(f"Сообщение от {addr}: {message}")
|
||||||
|
modified = message[::-1].upper() + "!!"
|
||||||
|
|
||||||
|
server.sendto(modified.encode(), addr)
|
||||||
|
|
1
tcp_client1.py.save
Normal file
1
tcp_client1.py.save
Normal file
@ -0,0 +1 @@
|
|||||||
|
pp
|
9
tcp_client2.py
Normal file
9
tcp_client2.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
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.sendall(b'exit')
|
||||||
|
client.close()
|
Loading…
Reference in New Issue
Block a user