Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ПИ20-3 Храмцова Е.Е. #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions server.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
import socket
import datetime

sock = socket.socket()

try:
sock.bind(('', 80))
print("Using port 80")
sock.bind(('', 83))
print("Используем порт 83")
except OSError:
sock.bind(('', 8080))
print("Using port 8080")
print("Используем порт 8080")

sock.listen(5)

conn, addr = sock.accept()
print("Connected", addr)
print("Подключено", addr)

data = conn.recv(8192)
msg = data.decode()

print(msg)

resp = """HTTP/1.1 200 OK

nowdate = datetime.datetime.utcnow().strftime(r"%a, %d %b %Y %H:%M:%S GMT")
print(nowdate)
content = "Hello world!"
content_length = len(content)
resp = f"""HTTP/1.1 200 OK
Date: {nowdate}
Content-length: {content_length}
Server: SelfMadeServer v0.0.1
Content-type: text/html
Content-type: text/html; charset = utf8
Connection: close

Hello, webworld!"""
{content}"""

conn.send(resp.encode())

Expand Down