-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain-server.py
More file actions
executable file
·56 lines (48 loc) · 1.76 KB
/
main-server.py
File metadata and controls
executable file
·56 lines (48 loc) · 1.76 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
'''
ULIMA - Programacion Internet
Servidor que reponde texto
'''
__author__ = "Hernan Quintana"
__copyright__ = "Copyright 2015, ULIMA-PI"
__credits__ = ["Hernan Quintana", "https://wiki.python.org/moin/BaseHttpServer"]
__license__ = "GPL"
__version__ = "1.0.0"
__maintainer__ = "Hernan Quintana"
__email__ = "hquintan@ulima.edu.pe"
__status__ = "Production"
import time
import BaseHTTPServer
HOST_NAME = 'localhost'
PORT_NUMBER = 80
class MyServerHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(s):
"""Respond to a GET request."""
s.send_response(200)
s.send_header("Content-type", "text/text")
s.end_headers()
print s.path
if s.path == "url1":
s.wfile.write("<html><head><title>Demo 1 - Programacion Internet</title></head>")
s.wfile.write("<body><p>Esto es una prueba</p></body>")
elif s.path == "url2":
s.wfile.write("<html><head><title>Demo 1 - Programacion Internet</title></head>")
s.wfile.write("<body>")
s.wfile.write("<h1>Titulo</h1>")
s.wfile.write("<p>Este un parrafo</p>")
s.wfile.write("<div>Esta es un div (cuadro)</div>")
s.wfile.write("</body>")
elif s.path == "url":
s.wfile.write("Hola mundo!!")
else:
s.send_error(404, "Recurso no encontrado")
return
if __name__ == '__main__':
server_class = BaseHTTPServer.HTTPServer
httpd = server_class((HOST_NAME, PORT_NUMBER), MyServerHandler)
print time.asctime(), "Server iniciando - %s:%s" % (HOST_NAME, PORT_NUMBER)
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
print time.asctime(), "Server parado - %s:%s" % (HOST_NAME, PORT_NUMBER)