Skip to content

Commit

Permalink
#49 - Cosmetic change and use a data-pattern that is easier to debug.
Browse files Browse the repository at this point in the history
  • Loading branch information
PerMalmberg committed Aug 4, 2019
1 parent a3634a4 commit 91c2ae8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/smooth/application/network/http/HTTPServerClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ namespace smooth::application::network::http
}
}
}
while (!operations.empty() &&
res == ResponseStatus::NoData); // Process next operation as long as no data is sent.
while (!operations.empty()
&& res == ResponseStatus::NoData); // Process next operation as long as no data is sent.
}


Expand Down
47 changes: 39 additions & 8 deletions test/http_server_test/web_root/websocket.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,42 @@
}

function send() {
document.getElementById("total_count").innerText = "0";
var block_size = parseInt(document.getElementById("block_size").value);

var remaining = parseInt(document.getElementById("to_send").value);

console.log("Sending " + remaining + " bytes");

var i = 0;
let id = 0;
let i = 0;

let msg = {};

var msg = {};
let characters = "abcdefghijklmonpqrstuvwxyz1234567890";

while (remaining > block_size) {
msg["message_id"] = i;
msg["data"] = "a".repeat(block_size);
msg["message_id"] = id;
msg["data"] = "";
for(i = 0; i < block_size; ++i) {
msg["data"] += characters.charAt(i%characters.length);
}
msg["length"] = block_size;

socket.send(JSON.stringify(msg));

remaining -= block_size;
++i;
++id;
}

if (remaining > 0) {
msg["message_id"] = i;
msg["data"] = "a".repeat(remaining);
msg["message_id"] = id;
if(msg["data"] === undefined) {
msg["data"] = "";
}
for(; i < remaining; ++i) {
msg["data"] += characters.charAt(i%characters.length);
}
msg["length"] = remaining;
socket.send(JSON.stringify(msg));
}
Expand All @@ -86,6 +98,25 @@
document.getElementById("total_count").innerText = "0";
}

function cont_send() {

const interval = 5000;

if(document.getElementById("continuous").checked)
{
let f = function() {
if(document.getElementById("continuous").checked) {
send();
setTimeout(f, interval);
}
};

if(document.getElementById("continuous").checked) {
setTimeout(f, interval);
}
}
}

</script>
</head>
<body>
Expand All @@ -104,10 +135,10 @@
<br/>
Amount to send: <input type="text" id="to_send" value="65535"/>
<button onclick="send();">Send</button>
<label for="continuous">Continuous</label><input type="checkbox" id="continuous" onchange="cont_send();"/>
<br/>
Total count:
<div id="total_count">0</div>
<button onclick="reset_total();">Reset total</button>
<br/>
<br/>
<label for="id">ID</label><textarea id="id"></textarea>
Expand Down

0 comments on commit 91c2ae8

Please sign in to comment.