Permalink
Browse files

Updated tests

  • Loading branch information...
1 parent 92e968e commit f4a62214e118dc5eccc7c0804b5c6aa28103a169 @zerodivisi0n zerodivisi0n committed Mar 21, 2012
View
@@ -62,14 +62,17 @@ wsServer = new WebSocketServer({
wsServer.on('connect', function(connection) {
if (debug) console.log((new Date()) + " Connection accepted" +
" - Protocol Version " + connection.webSocketVersion);
+ function sendCallback(err) {
+ if (err) console.error("send() error: " + err);
+ }
connection.on('message', function(message) {
if (message.type === 'utf8') {
if (debug) console.log("Received utf-8 message of " + message.utf8Data.length + " characters.");
- connection.sendUTF(message.utf8Data);
+ connection.sendUTF(message.utf8Data, sendCallback);
}
else if (message.type === 'binary') {
if (debug) console.log("Received Binary Message of " + message.binaryData.length + " bytes");
- connection.sendBytes(message.binaryData);
+ connection.sendBytes(message.binaryData, sendCallback);
}
});
connection.on('close', function(reasonCode, description) {
@@ -111,13 +111,17 @@ client.on('connect', function(connection) {
byteCounter = 0;
}
};
+
+ function sendUTFCallback(err) {
+ if (err) console.error("sendUTF() error: " + err);
+ }
function requestData() {
if (args.binary) {
- connection.sendUTF('sendBinaryMessage|' + requestedLength);
+ connection.sendUTF('sendBinaryMessage|' + requestedLength, sendUTFCallback);
}
else {
- connection.sendUTF('sendMessage|' + requestedLength);
+ connection.sendUTF('sendMessage|' + requestedLength, sendUTFCallback);
}
requestedLength += Math.ceil(Math.random() * 1024);
}
@@ -95,6 +95,9 @@ router.mount('*', 'fragmentation-test', function(request) {
connection.on('message', function(message) {
if (message.type === 'utf8') {
+ function sendCallback(err) {
+ if (err) console.error("send() error: " + err);
+ }
var length = 0;
var match = /sendMessage\|(\d+)/.exec(message.utf8Data);
if (match) {
@@ -107,7 +110,7 @@ router.mount('*', 'fragmentation-test', function(request) {
longLorem = longLorem.slice(0,requestedLength);
length = Buffer.byteLength(longLorem);
if (length > 0) {
- connection.sendUTF(longLorem);
+ connection.sendUTF(longLorem, sendCallback);
console.log((new Date()) + " sent " + length + " byte utf-8 message to " + connection.remoteAddress);
}
return;
@@ -123,7 +126,7 @@ router.mount('*', 'fragmentation-test', function(request) {
buffer[i] = Math.ceil(Math.random()*255);
}
- connection.sendBytes(buffer);
+ connection.sendBytes(buffer, sendCallback);
console.log((new Date()) + " sent " + buffer.length + " byte binary message to " + connection.remoteAddress);
return;
}
@@ -53,14 +53,17 @@ mirrorClient.on('connect', function(connection) {
connection.on('close', function() {
console.log("lws-mirror-protocol Connection Closed");
});
+ function sendCallback(err) {
+ if (err) console.error("send() error: " + err);
+ }
function spamCircles() {
if (connection.connected) {
// c #7A9237 487 181 14;
var color = 0x800000 + Math.round(Math.random() * 0x7FFFFF);
var x = Math.round(Math.random() * 502);
var y = Math.round(Math.random() * 306);
var radius = Math.round(Math.random() * 30);
- connection.send("c #" + color.toString(16) + " " + x + " " + y + " " + radius + ";");
+ connection.send("c #" + color.toString(16) + " " + x + " " + y + " " + radius + ";", sendCallback);
setTimeout(spamCircles, 10);
}
}
@@ -91,6 +91,10 @@ var mirrorConnections = [];
var mirrorHistory = [];
+function sendCallback(err) {
+ if (err) console.error("send() error: " + err);
+}
+
router.mount('*', 'lws-mirror-protocol', function(request) {
var cookies = [
{
@@ -115,7 +119,7 @@ router.mount('*', 'lws-mirror-protocol', function(request) {
var historyString = mirrorHistory.join('');
console.log((new Date()) + " sending mirror protocol history to client; " + connection.remoteAddress + " : " + Buffer.byteLength(historyString) + " bytes");
- connection.send(historyString);
+ connection.send(historyString, sendCallback);
}
mirrorConnections.push(connection);
@@ -134,7 +138,7 @@ router.mount('*', 'lws-mirror-protocol', function(request) {
// Re-broadcast the command to all connected clients
mirrorConnections.forEach(function (outputConnection) {
- outputConnection.send(message.utf8Data);
+ outputConnection.send(message.utf8Data, sendCallback);
});
}
});
@@ -161,7 +165,7 @@ router.mount('*', 'dumb-increment-protocol', function(request) {
var number = 0;
connection.timerInterval = setInterval(function() {
- connection.send((number++).toString(10));
+ connection.send((number++).toString(10), sendCallback);
}, 50);
connection.on('close', function() {
clearInterval(connection.timerInterval);

0 comments on commit f4a6221

Please sign in to comment.