forked from algoritmosmathpy/algoritmos-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServidor HTTP Con Python.py
More file actions
31 lines (22 loc) · 1018 Bytes
/
Copy pathServidor HTTP Con Python.py
File metadata and controls
31 lines (22 loc) · 1018 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
"""
Programa que abre un servidor HTTP en el puerto 8000, que muestra un mensaje.
"""
#Importamos las siguienetes librerias
from http.server import HTTPServer, BaseHTTPRequestHandler
#Creamos una clase que heredara los metodos de BaseHTPPRequestHandler
class serverHTTP(BaseHTTPRequestHandler):
def do_GET(self):
#Enviamos una respuesta al servidor, en este caso 200 (OK)
self.send_response(200)
#Enviamos las Cabezeras, el contenido del documento sera HTML
self.send_header('Content-type', 'text/HTML; charset=utf-8')
self.end_headers()
#Variable que contendra el mensaje que mostraremos en el servidor en formato HTML
self.mensaje = "<h1>Hola MathPy!!!</h1>"
#Escribimos en el documento del servidor
self.wfile.write(self.mensaje.encode())
if __name__ == '__main__':
server_address = ((''), 8000)
httpd = HTTPServer(server_address, serverHTTP)
print("El servidor esta abierto en el puerto 8000, dirigete a http://localhost:8000/")
httpd.serve_forever()