Created
February 22, 2020 21:04
-
-
Save ppsirg/964316389d751b11abcb1db40f87764d to your computer and use it in GitHub Desktop.
cliente sencillo tornado javascript E6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="es" dir="ltr"> | |
<head> | |
<meta charset="utf-8"> | |
<title>mi pagina</title> | |
</head> | |
<body> | |
<h1>hola amigos</h1> | |
<h2 id="mostrarfecha"></h2> | |
</body> | |
<script type="text/javascript"> | |
function actualizar_fecha() { | |
console.log('actualizando fecha'); | |
let indicador = document.getElementById('mostrarfecha'); | |
fetch('/ping') | |
.then(resp => { | |
console.log(resp); | |
return resp.json(); | |
}) | |
.then(res => { | |
indicador.innerHTML = res.hora; | |
}) | |
.catch(err => { | |
console.log(err); | |
indicador.innerHTML = 'hay un error'; | |
}) | |
} | |
window.setInterval(actualizar_fecha, 3000); | |
</script> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from tornado.ioloop import IOLoop | |
import tornado.web | |
from tornado import gen | |
from datetime import datetime | |
class probeHandler(tornado.web.RequestHandler): | |
def get(self, *args, **kwargs): | |
self.render('mi_pagina.html') | |
def post(self, *args, **kwargs): | |
print(args) | |
print(kwargs) | |
self.write({'response': 'posted it'}) | |
class pingHandler(tornado.web.RequestHandler): | |
"""docstring for pingHandler.""" | |
def get(self, *arg, **kwargs): | |
self.write({'respuesta': 'pong', 'hora': str(datetime.now())}) | |
def make_app(): | |
return tornado.web.Application([ | |
(r"/", probeHandler), | |
(r'/ping', pingHandler) | |
]) | |
if __name__ == "__main__": | |
app = make_app() | |
app.listen(8888) | |
current = IOLoop.current() | |
current.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment