whiteshark and check TPC and UDP

This commit is contained in:
Елизавета Данилова 2026-04-27 22:19:28 +03:00
commit 66bf5285c4
5 changed files with 61 additions and 0 deletions

BIN
.gitignore vendored Normal file

Binary file not shown.

12
tcp_client.py Normal file
View File

@ -0,0 +1,12 @@
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('127.0.0.1', 10000))
message = input("Введите сообщение: ")
client.sendall(message.encode())
data = client.recv(1024)
print(f"Ответ от сервера: {data.decode()}")
client.close()

26
tcp_server.py Normal file
View File

@ -0,0 +1,26 @@
import socket
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(("0.0.0.0", 10000))
server.listen(1)
print("TCP сервер запущен на порту 10000")
while True:
conn, addr = server.accept()
print(f"Подключение от {addr}")
data = conn.recv(1024)
if not data:
break
response = data.upper()
conn.sendall(response)
print(f"Отправлено: {response}")
conn.close()
if response == b'EXIT':
print("Завершение сервера")
break
server.close()

11
udp_client.py Normal file
View File

@ -0,0 +1,11 @@
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
message = input("Введите сообщение: ")
client.sendto(message.encode(), ('127.0.0.1', 10001))
data, _ = client.recvfrom(1024)
print(f"Ответ от сервера: {data.decode()}")
client.close()

12
udp_server.py Normal file
View File

@ -0,0 +1,12 @@
import socket
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server.bind(('0.0.0.0', 10001))
print("UDP сервер запущен на порту 10001")
while True:
data, addr = server.recvfrom(1024)
print(f"Сообщение от {addr}: {data.decode()}")
modified_data = data.upper()[::-1]
server.sendto(modified_data, addr)