Skip to content

Commit

Permalink
FlashSocket transport is properly working now.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjoes committed Nov 18, 2011
1 parent 0612c57 commit 8d86d5e
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 12 deletions.
Binary file added examples/WebSocketMain.swf
Binary file not shown.
1 change: 0 additions & 1 deletion examples/crosssite/index.html
Expand Up @@ -3,7 +3,6 @@
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="socket.io.js"></script>
<script>WEB_SOCKET_SWF_LOCATION = 'http://cdn.socket.io/stable/WebSocketMain.swf';</script>
<script>
$(function() {
var s = new io.connect('http://localhost:8002', {
Expand Down
1 change: 0 additions & 1 deletion examples/gen/index.html
Expand Up @@ -3,7 +3,6 @@
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="socket.io.js"></script>
<script>WEB_SOCKET_SWF_LOCATION = 'http://cdn.socket.io/stable/WebSocketMain.swf';</script>
<script>
$(function() {
var query = new io.connect('http://localhost:8001');
Expand Down
1 change: 0 additions & 1 deletion examples/multiplexed/index.html
Expand Up @@ -3,7 +3,6 @@
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="socket.io.js"></script>
<script>WEB_SOCKET_SWF_LOCATION = 'http://cdn.socket.io/stable/WebSocketMain.swf';</script>
<script>
$(function() {
var sock = new io.connect('http://localhost:8001'),
Expand Down
1 change: 0 additions & 1 deletion examples/rpcping/index.html
Expand Up @@ -3,7 +3,6 @@
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="socket.io.js"></script>
<script>WEB_SOCKET_SWF_LOCATION = 'http://cdn.socket.io/stable/WebSocketMain.swf';</script>
<script>
$(function() {
var ping = new io.connect('http://localhost:8001');
Expand Down
4 changes: 3 additions & 1 deletion examples/transports/index.html
Expand Up @@ -3,7 +3,9 @@
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="socket.io.js"></script>
<script>WEB_SOCKET_SWF_LOCATION = 'http://cdn.socket.io/stable/WebSocketMain.swf';</script>
<script>
WEB_SOCKET_SWF_LOCATION = 'WebSocketMain.swf';
</script>
<script>
var conn = null;
$(function() {
Expand Down
15 changes: 14 additions & 1 deletion examples/transports/transports.py
Expand Up @@ -20,6 +20,17 @@ def get(self):
self.render('../socket.io.js')


class WebSocketFileHandler(tornado.web.RequestHandler):
def get(self):
# Obviously, you want this on CDN, but for sake of
# example this approach will work.
self.set_header('Content-Type', 'application/x-shockwave-flash')

with open(op.join(ROOT, '../WebSocketMain.swf'), 'rb') as f:
self.write(f.read())
self.finish()


class ChatConnection(tornadio2.conn.SocketConnection):
# Class level variable
participants = set()
Expand All @@ -42,7 +53,9 @@ def on_close(self):
# Create application
application = tornado.web.Application(
ChatRouter.apply_routes([(r"/", IndexHandler),
(r"/socket.io.js", SocketIOHandler)]),
(r"/socket.io.js", SocketIOHandler),
(r"/WebSocketMain.swf", WebSocketFileHandler)
]),
flash_policy_port = 843,
flash_policy_file = op.join(ROOT, 'flashpolicy.xml'),
socket_io_port = 8001
Expand Down
2 changes: 1 addition & 1 deletion tornadio2/persistent.py
Expand Up @@ -80,6 +80,6 @@ def session_closed(self):
self._detach()


class TornadioFlashSocketHandler(WebSocketHandler):
class TornadioFlashSocketHandler(TornadioWebSocketHandler):
# Transport name
name = 'flashsocket'
8 changes: 3 additions & 5 deletions tornadio2/proto.py
Expand Up @@ -47,7 +47,7 @@ def default(self, o):
ERROR = '7'
NOOP = '8'

# utf-8 encoded frame separator
# socket.io frame separator
FRAME_SEPARATOR = u'\ufffd'


Expand Down Expand Up @@ -186,7 +186,7 @@ def json_dumps(msg):


def json_load(msg):
"""Load json
"""Load json-encoded object
`msg`
json encoded object
Expand All @@ -211,9 +211,7 @@ def decode_frames(data):
idx = 0
packets = []

frame_len = len(FRAME_SEPARATOR)

while data[idx:idx + frame_len] == FRAME_SEPARATOR:
while data[idx:idx + 1] == FRAME_SEPARATOR:
idx += 1

# Grab message length
Expand Down

0 comments on commit 8d86d5e

Please sign in to comment.