Skip to content

Commit 2a780eb

Browse files
committed
Test commit.
1 parent 4589117 commit 2a780eb

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
fin = open('tiny_html.html', 'r')
19+
html = fin.read()
20+
fin.close()
21+
22+
while True: # keep looking for new connections forever
23+
client, address = s.accept() # look for a connection
24+
data = client.recv(size)
25+
if data: # if the connection was closed there would be no data
26+
print "received: %s, sending it back"%data
27+
client.send(html)
28+
client.close()

0 commit comments

Comments
 (0)