Create a gist now

Instantly share code, notes, and snippets.

@bkad /websocket_client.py Secret
Last active Oct 8, 2015

What would you like to do?
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
connectWS(factory)
reactor.run()
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 = ws.stream.handler.socket.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)
server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment