Browse Source

Try again with websockets

master
Pete Shadbolt 8 years ago
parent
commit
2a6abed48c
3 changed files with 21 additions and 16 deletions
  1. +0
    -2
      abp/clifford.py
  2. +3
    -2
      server/static/main.js
  3. +18
    -12
      server/static/poll.js

+ 0
- 2
abp/clifford.py View File

@@ -146,8 +146,6 @@ try:
with open(temp("by_name.json")) as f:
by_name = json.load(f)


print "Loaded tables from cache"
except IOError:
# Spend time building the tables
unitaries = get_unitaries()


+ 3
- 2
server/static/main.js View File

@@ -31,6 +31,7 @@ function startMainLoop() {
scene = makeScene();
controls.addEventListener("change", render);
poll();
render();
}

// Someone resized the window
@@ -63,12 +64,12 @@ function init() {
controls = new THREE.OrbitControls(camera);

// Center the camera
// TODO: frustrum
controls.center.set(0, 0, 0);
controls.rotateSpeed = 0.2;
camera.position.set(0, 0, 20);
camera.position.set(0, 0, 40);

// Start polling
setInterval(poll, 1000);

// Run
startMainLoop();


+ 18
- 12
server/static/poll.js View File

@@ -1,19 +1,25 @@

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

xhr.onload = function() {
var state = JSON.parse(xhr.responseText);
updateScene(state);
var ws = new WebSocket("ws://localhost:5000/echo");
ws.onopen = function()
{
// Web Socket is connected, send data using send()
ws.send("Hello from the browser! I connected okay");
console.log("Sent a message to the server");
};

xhr.onerror = function(e){
//soft_console.innerHTML = "\n" + "Lost connection to server";
ws.onmessage = function (evt)
{
var received_msg = evt.data;
console.log("I got a message from the server:");
console.log(evt.data);
};
ws.onclose = function()
{
ws.send("Bye by from the browser");
console.log("Connection is closed...");
};

xhr.open("GET", "/state", true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.send();
}

function updateScene(state) {


Loading…
Cancel
Save