Created
September 18, 2018 05:06
-
-
Save xtpor/79e53fd9b2f0748be6dc0b3f06dd3c69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Load Testing</h1> | |
<div> | |
<input id="url" type="text"/> | |
<button id="start">Start</button> | |
</div> | |
<div id="output"> | |
</div> | |
<script> | |
var urlText = document.getElementById("url") | |
var startButton = document.getElementById("start") | |
var output = document.getElementById("output") | |
function log(text) { | |
output.innerHTML += text + "<br />" | |
} | |
startButton.onclick = function () { | |
var url = urlText.value | |
console.log(url) | |
log("Connecting to " + url) | |
start(url) | |
} | |
function start(url) { | |
var socket = new WebSocket(url) | |
socket.onopen = function () { | |
log("Connected.") | |
socket.send(JSON.stringify({name: "user login", data: {name: "hello"}})) | |
for (var i=0; i<10000; i++) { | |
socket.send(JSON.stringify({name: "user chat", data: {content: "hello world"}})) | |
} | |
log("10000 message sent.") | |
socket.close() | |
log("disconnected.") | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment