C++でWebsocket通信(書きかけ)

最終更新: 2017-07-29 01:06

見つけたなかではdhbaird/easywsclientが一番簡単

http://dev.classmethod.jp/server-side/ws/

client

<!DOCTYPE html>
<html>
<head>
    <script>
        function send() {
            ws.send(document.getElementById('msg').value);
        }
 
        var host = window.document.location.host.replace(/:.*/, '');
        var ws = new WebSocket('ws://' + host + ':8126/foo');
        ws.onmessage = function (event) {
            document.getElementById("messages").innerHTML += "<div>" + event.data + "</div>";
            console.log(event.data);
        };
    </script>
</head>
<body>
<strong>ws chat</strong><br>
<input type="text" id="msg"/>
<input type="button" value="send" onclick="send()"/>
<br>
<hr>
<div id="messages"/>
</body>
</html>