-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_html_server.py
More file actions
122 lines (107 loc) · 2.69 KB
/
Copy path_html_server.py
File metadata and controls
122 lines (107 loc) · 2.69 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import socket
html_code ="""
<!DOCTYPE html>
<html>
<head>
<title>Professional Website</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
background-color: #333;
color: #fff;
padding: 20px;
text-align: center;
}
header h1 {
margin: 0;
}
nav {
background-color: #444;
padding: 10px;
text-align: center;
}
nav a {
color: #fff;
text-decoration: none;
margin: 0 10px;
}
nav a:hover {
color: #ccc;
}
main {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
}
section {
background-color: #f7f7f7;
padding: 20px;
margin: 20px;
width: 80%;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
section h2 {
margin-top: 0;
}
footer {
background-color: #333;
color: #fff;
padding: 10px;
text-align: center;
clear: both;
}
</style>
</head>
<body>
<header>
<h1>Professional Website</h1>
</header>
<nav>
<a href="
<a href="#">About</a>
<a href="#">Contact</a>
</nav>
<main>
<section>
<h2>Welcome to our website</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sit amet nulla auctor, vestibulum magna sed, convallis ex.</p>
</section>
<section>
<h2>Our Services</h2>
<ul>
<li>Web Development</li>
<li>Mobile App Development</li>
<li>Digital Marketing</li>
</ul>
</section>
</main>
<footer>
<p>© 2023 Professional Website</p>
</footer>
</body>
</html>
"""
def main():
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = 'localhost'
port = 12345
server.bind((host, port))
server.listen(1)
print("server is on")
client, address = server.accept()
print(f"server connected with {address}")
while True:
data = client.recv(1024).decode()
print(f"reply >> {data}")
message = f"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n{html_code}"
client.sendall(message.encode())
client.close()
break
server.close()
if __name__ == "__main__":
main()