Explorar el Código

It's working now - Ctrl-C, polling etc are good

master
Pete Shadbolt hace 8 años
padre
commit
427d0674b5
Se han modificado 4 ficheros con 13 adiciones y 5 borrados
  1. +2
    -1
      server/index.html
  2. +1
    -1
      server/main.css
  3. +4
    -1
      server/main.js
  4. +6
    -2
      server/server.py

+ 2
- 1
server/index.html Ver fichero

@@ -9,6 +9,7 @@

<body>
<script src="main.js"></script>
Watching server on localhost:8000
Soft console:
<pre id="soft_console"></pre>
</body>
</html>

+ 1
- 1
server/main.css Ver fichero

@@ -1,3 +1,3 @@
body{
font-family: monospace;
font-family: sans-serif;
}

+ 4
- 1
server/main.js Ver fichero

@@ -1,11 +1,14 @@
var body;

function poll() {
var xhr = new XMLHttpRequest();

xhr.onload=function() {
console.log(xhr.responseText);
soft_console.innerHTML = "\n" + xhr.responseText;
};

xhr.onerror = function(e){
soft_console.innerHTML = "\n" + "Lost connection to server";
};

xhr.open("GET", "/state", true);


+ 6
- 2
server/server.py Ver fichero

@@ -7,6 +7,8 @@ import json
import threading
import time

state = 0

class VizHandler(SimpleHTTPRequestHandler):
""" Handles requests to the server """
def __init__(self, *args, **kwargs):
@@ -16,7 +18,7 @@ class VizHandler(SimpleHTTPRequestHandler):
self.send_response(200)
self.send_header('Content-Type', 'application/json')
self.end_headers()
self.wfile.write(json.dumps({"state":"here is the state"}))
self.wfile.write(json.dumps({"state":"{}".format(state)}))
def do_GET(self, *args, **kwargs):
parsed_path = urlparse.urlparse(self.path)
@@ -49,5 +51,7 @@ class VizServer(SocketServer.TCPServer):
if __name__ == '__main__':
server = VizServer()
server.start()
time.sleep(5)
while True:
state += 1
time.sleep(1)
server.shutdown()

Cargando…
Cancelar
Guardar