Refactor and add IETF-07 protocol version support.

- Add initial IETF-07 (HyBi-07) protocol version support. This version
  still uses base64 encoding since the API for binary support is not
  yet finalized.

- Move socket send and recieve functions into the WebSocketServer
  class instead of having the sub-class do this. This simplifies
  sub-classes somewhat. The send_frame routine now returns the number
  of frames that were unable to be sent. If this value is non-zero
  then the sub-class should call again when the socket is ready until
  the pending frames count is 0.

- Do traffic reporting in the main class instead.

- When the client is HyBi style (i.e. IETF-07) then use the
  sub-protocol header to select whether to do base64 encoding or
  simply send the frame data raw (binary). Update include/websock.js
  to send a 'base64' protocol selector. Once the API support binary,
  then the client will need to detect this and set the protocol to
  'binary'.
This commit is contained in:
Joel Martin
2011-05-01 22:17:04 -05:00
parent ff470ad704
commit 88b71ce171
11 changed files with 498 additions and 467 deletions
+9 -6
View File
@@ -6,14 +6,17 @@ Display UTF-8 encoding for 0-255.'''
import sys, os, socket, ssl, time, traceback
from select import select
sys.path.insert(0,os.path.dirname(__file__) + "/../utils/")
sys.path.insert(0,os.path.dirname(__file__) + "/../")
from websocket import WebSocketServer
if __name__ == '__main__':
print "val: hixie | hybi_base64 | hybi_binary"
for c in range(0, 256):
print "%d: %s" % (c, repr(WebSocketServer.encode(chr(c))[1:-1]))
#nums = "".join([chr(c) for c in range(0,256)])
#for char in WebSocketServer.encode(nums):
# print "%d" % ord(char),
#print repr(WebSocketServer.encode(nums))
hixie = WebSocketServer.encode_hixie(chr(c))
hybi_base64 = WebSocketServer.encode_hybi(chr(c), opcode=1,
base64=True)
hybi_binary = WebSocketServer.encode_hybi(chr(c), opcode=2,
base64=False)
print "%d: %s | %s | %s" % (c, repr(hixie), repr(hybi_base64),
repr(hybi_binary))