Make echo.py and load.py work again, after the refactoring of

websocket.py:

* With echo.py, which doesn't need any server configuration, we can
  just switch over our application class to inherit from
  WebSocketRequestHandler instead of WebSocketServer. Also, need to
  use the new method name new_websocket_client.

* With load.py, since we have the "delay" configuration, we need both
  a server class and a request handler.

Note that for both tests, I've removed the raising of
self.EClose(closed). This is incorrect. First of all, it's described
as "An exception before the WebSocket connection was established", so
not suitable for our case. Second, it will cause send_close to be
called twice. Finally, self.EClose is now in the WebSocketServer
class, and not a member of the request handler.
This commit is contained in:
Peter Åstrand (astrand)
2013-03-20 10:03:04 +01:00
parent 09f3ec7125
commit d0608a63b6
2 changed files with 17 additions and 17 deletions
+4 -5
View File
@@ -12,15 +12,15 @@ as taken from http://docs.python.org/dev/library/ssl.html#certificates
import os, sys, select, optparse
sys.path.insert(0,os.path.dirname(__file__) + "/../websockify")
from websocket import WebSocketServer
from websocket import WebSocketServer, WebSocketRequestHandler
class WebSocketEcho(WebSocketServer):
class WebSocketEcho(WebSocketRequestHandler):
"""
WebSockets server that echos back whatever is received from the
client. """
buffer_size = 8096
def new_client(self):
def new_websocket_client(self):
"""
Echo back whatever is received.
"""
@@ -49,7 +49,6 @@ class WebSocketEcho(WebSocketServer):
if closed:
self.send_close()
raise self.EClose(closed)
if __name__ == '__main__':
parser = optparse.OptionParser(usage="%prog [options] listen_port")
@@ -70,6 +69,6 @@ if __name__ == '__main__':
parser.error("Invalid arguments")
opts.web = "."
server = WebSocketEcho(**opts.__dict__)
server = WebSocketServer(WebSocketEcho, **opts.__dict__)
server.start_server()