-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
50 lines (42 loc) · 1.05 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
간단한 서버 코드입니다.
"""
from http.server import BaseHTTPRequestHandler, HTTPServer
def total(num1, num2):
"""
num1과 num2 더하기
"""
return num1 + num2
class SimpleServer(BaseHTTPRequestHandler):
"""
Server class
"""
def do_GET(self): # pylint: disable=invalid-name
"""
GET 요청 처리 함수입니다.
"""
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(
bytes(
f"""
<html><head>
<title>Server</title>
<meta charset="UTF-8">
</head>
<body>
<h1>우성의 실습용 서버입니다.</h1>
<p>5+10은 {total(5, 10)}입니다</p>
</body></html>
""",
"utf-8",
)
)
if __name__ == "__main__":
webServer = HTTPServer(("0.0.0.0", 8080), SimpleServer)
try:
webServer.serve_forever()
except KeyboardInterrupt:
pass
webServer.server_close()