Create a gist now

Instantly share code, notes, and snippets.

@bkad / Secret
Last active Oct 8, 2015

Poller not recognizing there's new data to be read
from twisted.internet import reactor
from autobahn.websocket import WebSocketClientFactory,WebSocketClientProtocol, connectWS
class EchoClientProtocol(WebSocketClientProtocol):
def onOpen(self):
self.sendMessage("1", False)
self.sendMessage("2", False)
if __name__ == '__main__':
factory = WebSocketClientFactory("ws://localhost:8000/echo")
factory.protocol = EchoClientProtocol
from gevent import pywsgi
from geventwebsocket.handler import WebSocketHandler
from select import poll
import select
def websocket_app(environ, start_response):
if environ["PATH_INFO"] == "/echo":
ws = environ["wsgi.websocket"]
poller = poll()
fileno =
poller.register(fileno, select.POLLIN)
while True:
events = dict(poller.poll())
if fileno in events:
data = ws.receive()
print data
server = pywsgi.WSGIServer(("", 8000), websocket_app, handler_class=WebSocketHandler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment