Commit 1e633bc8 authored by Joel Martin's avatar Joel Martin

wstest*. Fix Opera problems. Flash policy. Misc bugs.

Lame. Opera doesn't support javascript reduce().

Also, Opera seems to just plain be pathetic when it comes to
delivering the web-socket-js events. Around 1/5 to 1/3 of all received
packets are never received as an event at all.

- Change default delay for send side to 10ms.

- Use a textarea for errors so that even without console.* support
  (ala firebug) we still see the errors that are happening.
parent 9e12c1a9
...@@ -24,14 +24,30 @@ ...@@ -24,14 +24,30 @@
</tr> </tr>
</table> </table>
<br>
Errors:<br>
<textarea id="error" style="font-size: 9;" cols=80 rows=25></textarea>
</body> </body>
<!-- Uncomment to activate firebug lite -->
<!--
<script type='text/javascript'
src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
-->
<script src="include/mootools.js"></script> <script src="include/mootools.js"></script>
<script src="include/base64.js"></script> <script src="include/base64.js"></script>
<script src="include/util.js"></script> <script src="include/util.js"></script>
<script> <script>
function error(str) {
cell = $('error');
cell.innerHTML += errors + ": " + str + "\n";
cell.scrollTop = cell.scrollHeight;
}
var host = null, port = null, sendDelay = 0; var host = null, port = null, sendDelay = 0;
var ws = null, update_ref = null, send_ref = null; var ws = null, update_ref = null, send_ref = null;
var sent = 0, received = 0, errors = 0; var sent = 0, received = 0, errors = 0;
...@@ -59,13 +75,13 @@ ...@@ -59,13 +75,13 @@
last = String.fromCharCode(decoded.pop()); last = String.fromCharCode(decoded.pop());
if (first != "^") { if (first != "^") {
console.error("Packet missing start char '^'");
errors++; errors++;
error("Packet missing start char '^'");
return; return;
} }
if (last != "$") { if (last != "$") {
console.error("Packet missing end char '$'");
errors++; errors++;
error("Packet missing end char '$'");
return; return;
} }
arr = decoded.map(function(num) { arr = decoded.map(function(num) {
...@@ -74,24 +90,29 @@ ...@@ -74,24 +90,29 @@
cnt = arr[0]; cnt = arr[0];
length = arr[1]; length = arr[1];
chksum = arr[2]; chksum = arr[2];
nums = arr[3]; nums = arr[3];
//console.log(" length:" + length + " chksum:" + chksum + " nums:" + nums); //console.log(" length:" + length + " chksum:" + chksum + " nums:" + nums);
if (cnt != recv_cnt) { if (cnt != recv_cnt) {
console.error("Expected count " + recv_cnt + " but got " + cnt);
recv_cnt = parseInt(cnt,10) + 1; // Back on track
errors++; errors++;
error("Expected count " + recv_cnt + " but got " + cnt);
recv_cnt = parseInt(cnt,10) + 1; // Back on track
return; return;
} }
recv_cnt++; recv_cnt++;
if (nums.length != length) { if (nums.length != length) {
console.error("Expected length " + length + " but got " + nums.length);
errors++; errors++;
error("Expected length " + length + " but got " + nums.length);
return; return;
} }
real_chksum = nums.split('').reduce(add); //real_chksum = nums.reduce(add);
real_chksum = 0;
for (var i=0; i < nums.length; i++) {
real_chksum += parseInt(nums.charAt(i), 10);
}
if (real_chksum != chksum) { if (real_chksum != chksum) {
console.error("Expected chksum " + chksum + " but real chksum is " + real_chksum);
errors++ errors++
error("Expected chksum " + chksum + " but real chksum is " + real_chksum);
return; return;
} }
received++; received++;
...@@ -109,7 +130,11 @@ ...@@ -109,7 +130,11 @@
for (var i=0; i < length; i++) { for (var i=0; i < length; i++) {
numlist.push( Math.floor(Math.random()*10) ); numlist.push( Math.floor(Math.random()*10) );
} }
chksum = numlist.reduce(add); //chksum = numlist.reduce(add);
chksum = 0;
for (var i=0; i < numlist.length; i++) {
chksum += parseInt(numlist[i], 10);
}
var nums = numlist.join(''); var nums = numlist.join('');
arr.pushStr("^" + send_cnt + ":" + length + ":" + chksum + ":" + nums + "$") arr.pushStr("^" + send_cnt + ":" + length + ":" + chksum + ":" + nums + "$")
send_cnt ++; send_cnt ++;
...@@ -191,14 +216,14 @@ ...@@ -191,14 +216,14 @@
/* If no builtin websockets then load web_socket.js */ /* If no builtin websockets then load web_socket.js */
if (! window.WebSocket) { if (! window.WebSocket) {
console.log("Loading web-socket-js flash bridge"); console.log("Loading web-socket-js flash bridge");
var extra = "<script src='web-socket-js/swfobject.js'><\/script>"; var extra = "<script src='include/web-socket-js/swfobject.js'><\/script>";
extra += "<script src='web-socket-js/FABridge.js'><\/script>"; extra += "<script src='include/web-socket-js/FABridge.js'><\/script>";
extra += "<script src='web-socket-js/web_socket.js'><\/script>"; extra += "<script src='include/web-socket-js/web_socket.js'><\/script>";
document.write(extra); document.write(extra);
} }
window.onload = function() { window.onload = function() {
WebSocket.__swfLocation = "web-socket-js/WebSocketMain.swf"; WebSocket.__swfLocation = "include/web-socket-js/WebSocketMain.swf";
console.log("onload"); console.log("onload");
var url = document.location.href; var url = document.location.href;
$('host').value = (url.match(/host=([^&#]*)/) || ['',''])[1]; $('host').value = (url.match(/host=([^&#]*)/) || ['',''])[1];
......
...@@ -18,19 +18,20 @@ WebSocket-Protocol: sample\r ...@@ -18,19 +18,20 @@ WebSocket-Protocol: sample\r
policy_response = """<cross-domain-policy><allow-access-from domain="*" to-ports="*" /></cross-domain-policy>""" policy_response = """<cross-domain-policy><allow-access-from domain="*" to-ports="*" /></cross-domain-policy>"""
def handshake(client): def do_handshake(client):
handshake = client.recv(1024) handshake = client.recv(1024)
print "Handshake [%s]" % handshake print "Handshake [%s]" % handshake
if handshake.startswith("<policy-file-request/>"): if handshake.startswith("<policy-file-request/>"):
print "Sending:", policy_response print "Sending flash policy response"
client.send(policy_response) client.send(policy_response)
handshake = client.recv(1024) client.close()
print "Handshake [%s]" % handshake return False
req_lines = handshake.split("\r\n") req_lines = handshake.split("\r\n")
_, path, _ = req_lines[0].split(" ") _, path, _ = req_lines[0].split(" ")
_, origin = req_lines[4].split(" ") _, origin = req_lines[4].split(" ")
_, host = req_lines[3].split(" ") _, host = req_lines[3].split(" ")
client.send(server_handshake % (origin, host, path)) client.send(server_handshake % (origin, host, path))
return True
def traffic(token="."): def traffic(token="."):
sys.stdout.write(token) sys.stdout.write(token)
...@@ -117,7 +118,7 @@ def generate(): ...@@ -117,7 +118,7 @@ def generate():
buf = "\x00" + b64encode(data) + "\xff" buf = "\x00" + b64encode(data) + "\xff"
return buf return buf
def responder(client, delay=500): def responder(client, delay=10):
global errors global errors
cqueue = [] cqueue = []
cpartial = "" cpartial = ""
...@@ -155,7 +156,7 @@ def responder(client, delay=500): ...@@ -155,7 +156,7 @@ def responder(client, delay=500):
client.send(generate()) client.send(generate())
traffic("<") traffic("<")
def start_server(listen_port, delay=500): def start_server(listen_port, delay=10):
global errors, send_cnt, recv_cnt global errors, send_cnt, recv_cnt
lsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) lsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
lsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) lsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
...@@ -167,7 +168,8 @@ def start_server(listen_port, delay=500): ...@@ -167,7 +168,8 @@ def start_server(listen_port, delay=500):
print 'listening on port %s' % listen_port print 'listening on port %s' % listen_port
csock, address = lsock.accept() csock, address = lsock.accept()
print 'Got client connection from %s' % address[0] print 'Got client connection from %s' % address[0]
handshake(csock) if not do_handshake(csock):
continue
send_cnt = 0 send_cnt = 0
recv_cnt = 0 recv_cnt = 0
...@@ -188,7 +190,7 @@ if __name__ == '__main__': ...@@ -188,7 +190,7 @@ if __name__ == '__main__':
if len(sys.argv) == 3: if len(sys.argv) == 3:
delay = int(sys.argv[2]) delay = int(sys.argv[2])
else: else:
delay = 500 delay = 10
except: except:
print "Usage: <listen_port> [delay_ms]" print "Usage: <listen_port> [delay_ms]"
sys.exit(1) sys.exit(1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment