This commit is contained in:
Crai-cry 2026-04-16 18:12:17 +03:00
commit ba3f047f75
7 changed files with 51 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.venv/
__pycache__/
*.pyc
output.txt

1
README.md Normal file
View File

@ -0,0 +1 @@
1 commit

0
requirements.txt Normal file
View File

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'hello server')
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', 10001))
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', 10001))
print("UDP ñåðâåð çàïóùåí")
while True:
data, addr = server.recvfrom(1024)
print(f"Ñîîáùåíèå îò {addr}: {data.decode()}")
server.sendto(data.upper(), addr)