Skip to content

Commit 6019659

Browse files
committed
set up assignment for week 2
1 parent 9d8e950 commit 6019659

File tree

9 files changed

+90
-0
lines changed

9 files changed

+90
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Complete your HTTP Web Server. Accomplish as many of the following goals as
2+
you are able:
3+
4+
* If you were unable to complete the first five steps in class, circle back
5+
and finish them
6+
7+
* Complete the 'Bonus point' parts from the first five steps, if you haven't
8+
already done so
9+
10+
* Format your directory listing as HTML
11+
12+
* In the HTML directory listing, make the files clickable links
13+
14+
* Add a new, dynamic endpoint. If the URI /time-page is requested, return an
15+
HTML page with the current time displayed.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
3+
import socket
4+
5+
host = '' # listen on all connections (WiFi, etc)
6+
port = 50000
7+
backlog = 5 # how many connections can we stack up
8+
size = 1024 # number of bytes to receive at once
9+
10+
## create the socket
11+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
12+
# set an option to tell the OS to re-use the socket
13+
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
14+
15+
# the bind makes it a server
16+
s.bind( (host,port) )
17+
s.listen(backlog)
18+
19+
while True: # keep looking for new connections forever
20+
client, address = s.accept() # look for a connection
21+
data = client.recv(size)
22+
if data: # if the connection was closed there would be no data
23+
print "received: %s, sending it back"%data
24+
client.send(data)
25+
client.close()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<html>
2+
<body>
3+
<h1>This is a header</h1>
4+
<p>
5+
and this is some regular text
6+
</p>
7+
<p>
8+
and some more
9+
</p>
10+
</body>
11+
</html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
5+
<h1>My First Heading</h1>
6+
7+
<p>My first paragraph.</p>
8+
9+
</body>
10+
</html>
11+
14.8 KB
Loading
143 KB
Loading
8.55 KB
Loading
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
make_time.py
5+
6+
simple script that returns and HTML page with the current time
7+
"""
8+
9+
import datetime
10+
11+
time_str = datetime.datetime.now().isoformat()
12+
13+
html = """
14+
<http>
15+
<body>
16+
<h2> The time is: </h2>
17+
<p> %s <p>
18+
</body>
19+
</http>
20+
"""% time_str
21+
22+
print html
23+
24+
25+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This is a very simple text file.
2+
Just to show that we can server it up.
3+
It is three lines long.

0 commit comments

Comments
 (0)