From 2d068f7b55afbde8cbe6ed417d3e4480347b43d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9E=D1=80=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=D0=BE?= <90414850+6Nkita9@users.noreply.github.com> Date: Wed, 24 Nov 2021 15:38:20 +0300 Subject: [PATCH 1/6] Update server.py --- server.py | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/server.py b/server.py index 9ed7429..b1d95cf 100644 --- a/server.py +++ b/server.py @@ -1,31 +1,35 @@ import socket - +from threading import Thread + +def working(conn, addr): + print(f'{addr} was connected') + + user = conn.recv(1024).decode() + print(user) + request_from_server = user.split(" ")[1] + if request_from_server == '/': + with open('index.html', 'rb') as file: + site = file.read() + conn.send(site) + if request_from_server == '/index.html': + with open('index.html', 'rb') as file: + site = file.read() + conn.send(site) + + else: + with open('error.html', 'rb') as file: + site = file.read() + conn.send(site) + + sock = socket.socket() - try: sock.bind(('', 80)) - print("Using port 80") except OSError: sock.bind(('', 8080)) - print("Using port 8080") - +print("Сервер запущен") sock.listen(5) - -conn, addr = sock.accept() -print("Connected", addr) - -data = conn.recv(8192) -msg = data.decode() - -print(msg) - -resp = """HTTP/1.1 200 OK -Server: SelfMadeServer v0.0.1 -Content-type: text/html -Connection: close - -Hello, webworld!""" - -conn.send(resp.encode()) - -conn.close() \ No newline at end of file +while True: + conn, addr = sock.accept() + thread = Thread(target=working, args=(conn, addr,)) + thread.start() From 90916eb97b803ed2171b0c2552c6745d92424e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9E=D1=80=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=D0=BE?= <90414850+6Nkita9@users.noreply.github.com> Date: Wed, 24 Nov 2021 15:40:14 +0300 Subject: [PATCH 2/6] Add files via upload --- error.html | 15 +++++++++++++++ index.html | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 error.html create mode 100644 index.html diff --git a/error.html b/error.html new file mode 100644 index 0000000..7a4737f --- /dev/null +++ b/error.html @@ -0,0 +1,15 @@ + + +
+ + + +