forked from boostorg/beast
Add websocket-chat-multi example:
This is the multi-threaded io_context version of the CppCon2018 WebSocket chat server and client example.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>WebSocket Chat - CppCon2018</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>WebSocket Chat</h1>
|
||||
<p>Source code: <a href="https://github.com/vinniefalco/CppCon2018">https://github.com/vinniefalco/CppCon2018</a></p>
|
||||
|
||||
Server URI: <input class="draw-border" id="uri" size="47" value="ws://localhost:8080" style="margin-bottom: 5px;">
|
||||
<button class="echo-button" id="connect">Connect</button>
|
||||
<button class="echo-button" id="disconnect">Disconnect</button><br>
|
||||
Your Name: <input class="draw-border" id="userName" size=47 style="margin-bottom: 5px;"><br>
|
||||
|
||||
<pre id="messages" style="width: 600px; height: 400px; border: solid 1px #cccccc; margin-bottom: 5px;"></pre>
|
||||
|
||||
<div style="margin-bottom: 5px;">
|
||||
Message<br>
|
||||
<input class="draw-border" id="sendMessage" size="74" value="">
|
||||
<button class="echo-button" id="send">Send</button>
|
||||
</div>
|
||||
<script>
|
||||
var ws = null;
|
||||
|
||||
connect.onclick = function() {
|
||||
ws = new WebSocket(uri.value);
|
||||
ws.onopen = function(ev) {
|
||||
messages.innerText += "[connection opened]\n";
|
||||
};
|
||||
ws.onclose = function(ev) {
|
||||
messages.innerText += "[connection closed]\n";
|
||||
};
|
||||
ws.onmessage = function(ev) {
|
||||
messages.innerText += ev.data + "\n";
|
||||
};
|
||||
ws.onerror = function(ev) {
|
||||
messages.innerText += "[error]\n";
|
||||
console.log(ev);
|
||||
};
|
||||
};
|
||||
disconnect.onclick = function() {
|
||||
ws.close();
|
||||
};
|
||||
send.onclick = function() {
|
||||
ws.send(userName.value + ": " + sendMessage.value);
|
||||
sendMessage.value = "";
|
||||
};
|
||||
sendMessage.onkeyup = function(ev) {
|
||||
ev.preventDefault();
|
||||
if (event.keyCode === 13) {
|
||||
send.click();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user