-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyWebServer.py
More file actions
executable file
·34 lines (27 loc) · 984 Bytes
/
pyWebServer.py
File metadata and controls
executable file
·34 lines (27 loc) · 984 Bytes
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
#!/usr/bin/python
import socket
from optparse import OptionParser
from subprocess import call
parser=OptionParser()
parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="print verbose status messages")
parser.add_option("-p", dest="portnum", default='8888', help="set PORT for server")
(options, args) = parser.parse_args()
if options.verbose:
print options
HOST, PORT = '', int(options.portnum)
listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listen_socket.bind((HOST, PORT))
listen_socket.listen(1)
print 'Serving HTTP on port %s ...' % PORT
while True:
client_connection, client_address = listen_socket.accept()
request = client_connection.recv(1024)
print request
http_response = """\
HTTP/1.1 200 OK
Hello, World!
"""
client_connection.sendall(http_response)
call(["touch", "some_file"])
client_connection.close()