Does Firefox have a WebSocket message limit?
I've been playing around with WebSockets lately, as my lastest game project. I noticed a slight delay of messages and even dropping of messages when I hooked up the keyboard controller to the WebSocket client, which simply sends key presses/releases to the server.
So if I send multiple messages in rapid succession, Firefox seems to pause for some time between each message or even drop them if there are too many.
The same code runs fine in Chrome, with no delay or message dropping. Is this intentional?
Edit: Here is a simplified page in which the problem occurs to me:
<!DOCTYPE html>
<html lang="en">
<head>
<title>WebSocket Test</title>
<meta charset="utf-8"/>
<script>
socket = new WebSocket("ws://example.com/websockettest");
socket.onopen = function() { message("[[ Connected ]]"); }
socket.onclose = function()开发者_如何学Go { message("[[ Disconnected ]]"); }
socket.onmessage = function(e) { message(e.data); }
function message(msg) {
document.getElementById("messages").textContent += msg + "\n";
}
</script>
</head>
<body>
<input type="button" value="Send" onclick="socket.send('Hey!');"/>
<input type="button" value="Send two" onclick="socket.send('Hey once!');
socket.send('Hey twice.');"/>
<pre id="messages"></pre>
</body>
</html>
Note that it doesn't matter if I repeatedly punch the "Send" button or just press "Send two".
I've tested firefox-4.0.1 with noVNC with WebSockets manually enabled and it works without any message loss or delays (in either direction). noVNC sends a lot of traffic in both directions and any messages lost cause a protocol failure which I have never seen with any version of firefox 4 (alpha, beta, 4.0, 4.0.1) and any delays are very obvious because noVNC is highly interactive.
Your client side code looks fine, so my suspicion is that something different about how firefox acts on the wire is triggering a bug in either SuperWebSocket or your SuperWebSocket code. It sounds like you have a fairly simple server that you can reproduce this with. I suggest implementing an equivalent simple test server with a different framework such as Socket.IO (if you have access to a Linux system) or the Jetty WebSockets servelet. If it reproduces with one of those then you may have found a bug in firefox's WebSockets client and you should file a bug with Mozilla. If it doesn't reproduce there, then it's probably a bug in SuperWebSocket or in your use of it.
精彩评论