Созданы файлы: tcp_server.py, tcp_client.py, udp_server.py, udp_client.py, http_client_socket.py, http_client_requests.py, requests.txt, git_api.py, README.md, .gitignore
This commit is contained in:
commit
338a87723e
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
venv/
|
||||
__pycache__/
|
||||
.env
|
||||
*.pyc
|
||||
0
git_api.py
Normal file
0
git_api.py
Normal file
0
http_client_requests.py
Normal file
0
http_client_requests.py
Normal file
0
http_client_socket.py
Normal file
0
http_client_socket.py
Normal file
19
tcp_client.py
Normal file
19
tcp_client.py
Normal file
@ -0,0 +1,19 @@
|
||||
import socket
|
||||
|
||||
HOST = "127.0.0.1"
|
||||
PORT = 10000
|
||||
|
||||
def main():
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
client.connect((HOST, PORT))
|
||||
while True:
|
||||
msg = input("Введите сообщение (EXIT для выхода): ")
|
||||
client.sendall(msg.encode())
|
||||
data = client.recv(1024)
|
||||
print(f"Ответ от сервера: {data.decode()}")
|
||||
if msg.upper() == "EXIT":
|
||||
break
|
||||
client.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
30
tcp_server.py
Normal file
30
tcp_server.py
Normal file
@ -0,0 +1,30 @@
|
||||
import socket
|
||||
|
||||
HOST = "0.0.0.0"
|
||||
PORT = 10000
|
||||
|
||||
def main():
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
server.bind((HOST, PORT))
|
||||
server.listen(1)
|
||||
print(f"TCP сервер запущен на {HOST}:{PORT}")
|
||||
|
||||
while True:
|
||||
conn, addr = server.accept()
|
||||
print(f"Подключение от {addr}")
|
||||
while True:
|
||||
data = conn.recv(1024)
|
||||
if not data:
|
||||
break
|
||||
modified = data.upper()
|
||||
conn.sendall(modified)
|
||||
if modified == b"EXIT":
|
||||
break
|
||||
conn.close()
|
||||
if modified == b"EXIT":
|
||||
break
|
||||
|
||||
server.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
0
udp_client.py
Normal file
0
udp_client.py
Normal file
0
udp_server.py
Normal file
0
udp_server.py
Normal file
Loading…
Reference in New Issue
Block a user