Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to use standard SocketServer RequestHandler design #72

Merged
merged 43 commits into from
Nov 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b9e1295
Prepare for solving https://github.com/kanaka/websockify/issues/71:
Mar 14, 2013
4e33889
Prepare for fixing https://github.com/kanaka/websockify/issues/71:
Mar 14, 2013
208f83b
Prepare for fixing https://github.com/kanaka/websockify/issues/71:
Mar 14, 2013
7b3dd8a
Try to solve https://github.com/kanaka/websockify/issues/71 by
Mar 14, 2013
70eb75a
Fix error with modern Python 2.X versions:
Mar 18, 2013
debc926
Renamed CustomProxyServer to WebSocketProxy; this was the earlier name.
Mar 18, 2013
b05b773
Corrected last commit.
Mar 18, 2013
1eecc7b
Merge remote branch 'upstream/master'
Mar 18, 2013
95593ac
Merge branch 'master' of github.com:astrand/websockify
Mar 18, 2013
09f3ec7
Rename self.client to self.request, ie adapt to:
Mar 20, 2013
d0608a6
Make echo.py and load.py work again, after the refactoring of
Mar 20, 2013
f594d70
Removed unused import of SimpleHTTPRequestHandler.
Mar 20, 2013
f5e42ff
Move WebSocketProxy class so that it is defined after the
Mar 20, 2013
e964c1e
Let our ProxyRequestHandler be default. This allows you to inherit
Mar 20, 2013
bc91786
Improved class documentation.
Mar 20, 2013
ed109d7
Fix Python3 compatibility when using --libserver.
Mar 20, 2013
4dc7c0d
Merge commit '2d078e8cd83735dad7d98fadcece652d93e2a037'
Nov 27, 2013
6ddfaa8
Merge commit '33e9a21ce4e38d52f43fe775fb154fc71c09c827'
Nov 27, 2013
5f8cb96
Merge commit '477947ba96a00032ae35ac55fd02a4a5f485497e'
Nov 27, 2013
33a1bd2
Merge commit 'b7f255ce0b21dc42189205b1f0e46b4f1d9854f9'
Nov 27, 2013
19c8482
Merge commit '6d27b5d321978586ea1601f757ead73dfba03da7'
Nov 27, 2013
122985b
Merge commit 'd3ba23fa64d79eeb602ff1015ec31014fd8e9b35'
Nov 27, 2013
cf901dd
Merge commit '46450577c2fb119fc5bf0ac09664f22651a080d0'
Nov 27, 2013
b63d197
Merge commit '36fcd5784fa0825eedbf31d91bc42c970605ddb4'
Nov 27, 2013
611effd
Merge commit '36cb8f4676c7b5ff34bd22ad729e00e77efb6f00'
Nov 27, 2013
4071291
Merge commit '264f8fdd7f12bd5b9f6813fb8de81c55b6328d9b'
Nov 27, 2013
ff30e54
Merge commit 'ab389d4e7114d7ddbfd085591d336ea5cc06c00d'
Nov 27, 2013
08d37e0
Merge commit 'f30ad05c70ab2a43c9078e2f79da40f1dc0c60ec'
Nov 27, 2013
063c7de
Merge commit 'bff3c373b32ebf707085e3c677bfad19b44fa054'
Nov 27, 2013
fb4ac5a
Merge commit 'edde5cd0ff6059bddae10c9b9faf0b3e8f388a9e'
Nov 27, 2013
611da86
Merge commit 'a7fa97f0e14926cc4433483fcb7581e0b3782140'
Nov 27, 2013
cbf05f8
Merge commit '4459824cc8196ad78fe9258b6c560ad46fe4cd52'
Nov 27, 2013
131f9ea
Merge commit '477dce6cf86d61b20a394f3cbf3170e60d199658'
Nov 28, 2013
f58b49f
Merge commit 'a61ae52610642ae58e914dda705df8bb9c8213ec'
Nov 28, 2013
972b30d
Merge commit '0e5c3ecfda3b1506b41412052db75d84df2b4ae7'
Nov 28, 2013
3b802c0
Merge commit '32b0567343aee7753b2b6be1bc1ee9a69657ba26'
Nov 28, 2013
6022484
Merge commit 'b4e0b534d5d04d57265045b4baf49dd81555064b'
Nov 28, 2013
81e2a53
Merge commit '13c99bcf053f7f3af8ba84c0d963a9591e020f49'
Nov 28, 2013
b92528a
Merge commit 'c3acdc2e38f871e28ffda1847b4338c4b02296b8'
Nov 28, 2013
bc216fb
Merge commit 'a47be21f9fa69ddf8d888ff9e3c75cdfc9e31c00'
Nov 28, 2013
7ecfa4f
Merge commit 'a04edfe80f54b44df5a3579f71710560c6b7b4fc'
Nov 28, 2013
e246e98
Merge commit '34a1b68d79a13c03aa63b5c4194796341c9383fe'
Nov 28, 2013
db93395
Follow up on 131f9ea645ac6f00d98743a420d168033f99063a: Proper logging
Nov 28, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions tests/echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,43 @@

import os, sys, select, optparse
sys.path.insert(0,os.path.join(os.path.dirname(__file__), ".."))
from websockify.websocket import WebSocketServer
from websockify.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.
"""

cqueue = []
c_pend = 0
cpartial = ""
rlist = [self.client]
rlist = [self.request]

while True:
wlist = []

if cqueue or c_pend: wlist.append(self.client)
if cqueue or c_pend: wlist.append(self.request)
ins, outs, excepts = select.select(rlist, wlist, [], 1)
if excepts: raise Exception("Socket exception")

if self.client in outs:
if self.request in outs:
# Send queued target data to the client
c_pend = self.send_frames(cqueue)
cqueue = []

if self.client in ins:
if self.request in ins:
# Receive client data, decode it, and send it back
frames, closed = self.recv_frames()
cqueue.extend(frames)

if closed:
self.send_close()
raise self.EClose(closed)

if __name__ == '__main__':
parser = optparse.OptionParser(usage="%prog [options] listen_port")
Expand All @@ -70,6 +69,6 @@ def new_client(self):
parser.error("Invalid arguments")

opts.web = "."
server = WebSocketEcho(**opts.__dict__)
server = WebSocketServer(WebSocketEcho, **opts.__dict__)
server.start_server()

27 changes: 14 additions & 13 deletions tests/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,35 @@

import sys, os, select, random, time, optparse
sys.path.insert(0,os.path.join(os.path.dirname(__file__), ".."))
from websockify.websocket import WebSocketServer
from websockify.websocket import WebSocketServer, WebSocketRequestHandler

class WebSocketLoad(WebSocketServer):
class WebSocketLoadServer(WebSocketServer):

buffer_size = 65536

max_packet_size = 10000
recv_cnt = 0
send_cnt = 0

def __init__(self, *args, **kwargs):
self.errors = 0
self.delay = kwargs.pop('delay')

WebSocketServer.__init__(self, *args, **kwargs)


class WebSocketLoad(WebSocketRequestHandler):

max_packet_size = 10000

def new_websocket_client(self):
print "Prepopulating random array"
self.rand_array = []
for i in range(0, self.max_packet_size):
self.rand_array.append(random.randint(0, 9))

WebSocketServer.__init__(self, *args, **kwargs)

def new_client(self):
self.errors = 0
self.send_cnt = 0
self.recv_cnt = 0

try:
self.responder(self.client)
self.responder(self.request)
except:
print "accumulated errors:", self.errors
self.errors = 0
Expand All @@ -61,14 +63,13 @@ def responder(self, client):

if closed:
self.send_close()
raise self.EClose(closed)

now = time.time() * 1000
if client in outs:
if c_pend:
last_send = now
c_pend = self.send_frames()
elif now > (last_send + self.delay):
elif now > (last_send + self.server.delay):
last_send = now
c_pend = self.send_frames([self.generate()])

Expand Down Expand Up @@ -162,6 +163,6 @@ def check(self, frames):
parser.error("Invalid arguments")

opts.web = "."
server = WebSocketLoad(**opts.__dict__)
server = WebSocketLoadServer(WebSocketLoad, **opts.__dict__)
server.start_server()

Loading