Last active
August 29, 2015 13:57
-
-
Save ikatson/9374163 to your computer and use it in GitHub Desktop.
uwsgi + harakiri + websockets bug
This file contains 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
<html> | |
<head> | |
<script> | |
var polling = (function () { | |
var poll_error_timeout = 1; | |
var default_error_timeout = poll_error_timeout + 0; | |
var poll_error_max_timeout = 15; | |
function pollForEventsWebsockets() { | |
var s = new WebSocket('ws://localhost:8000/ws'); | |
var retry = function () { | |
console.log( | |
'retrying websocket connection in ' + poll_error_timeout); | |
setTimeout(pollForEventsWebsockets, poll_error_timeout * 1000); | |
poll_error_timeout = Math.min( | |
poll_error_max_timeout, poll_error_timeout * 2); | |
}; | |
s.onopen = function() { | |
console.log("Websocket connected"); | |
poll_error_timeout = default_error_timeout; | |
}; | |
s.onmessage = function(e) { | |
console.log('Received message', e.data); | |
poll_error_timeout = default_error_timeout; | |
}; | |
s.onerror = function(e) { | |
console.error(e); | |
}; | |
s.onclose = function(e) { | |
console.log('ws connection closed'); | |
retry(); | |
}; | |
} | |
pollForEventsWebsockets(); | |
return {} | |
}()); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains 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
[uwsgi] | |
master=true | |
harakiri=5 | |
gevent=100 | |
gevent-mokey= | |
http=127.0.0.1:8000 | |
http-websockets= | |
post-buffering= | |
file=wsgi.py | |
home=/tmp/uwsgienv |
This file contains 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 | |
import logging | |
log = logging.getLogger(__name__) | |
def handle_websocket(environ, start_response): | |
import uwsgi | |
uwsgi.websocket_handshake() | |
uwsgi.websocket_recv() | |
def application(environ, start_response): | |
if environ['PATH_INFO'] == '/ws': | |
return handle_websocket(environ, start_response) | |
start_response('200', [('Content-Type', 'text/html')]) | |
with open('index.html') as html: | |
return html.read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment