secret
Last active

Poller not recognizing there's new data to be read

  • Download Gist
websocket_client.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13
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()
websocket_server_select_poller.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
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()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.