Skip to content

Commit ec01b56

Browse files
authored
Add files via upload
1 parent ab35193 commit ec01b56

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

server.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import socket
2+
3+
sock = socket.socket()
4+
5+
try:
6+
sock.bind(('', 80))
7+
print("Using port 80")
8+
except OSError:
9+
sock.bind(('', 8080))
10+
print("Using port 8080")
11+
12+
sock.listen(5)
13+
14+
conn, addr = sock.accept()
15+
print("Connected", addr)
16+
17+
data = conn.recv(8192)
18+
msg = data.decode()
19+
20+
print(msg)
21+
22+
resp = """HTTP/1.1 200 OK
23+
Server: SelfMadeServer v0.0.1
24+
Content-type: text/html
25+
Connection: close
26+
27+
Hello, webworld!"""
28+
29+
conn.send(resp.encode())
30+
31+
conn.close()

0 commit comments

Comments
 (0)