Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
- <title>socket.io Flask client</title>
- <meta name="description" content="">
- <meta name="viewport" content="width=device-width">
- </head>
- <body>
- <input id="cmd" type="text" />
- <textarea id="value"></textarea><button id="sendBtn" type="button">Send</button>
- <div id="console"></div>
- <script src="/js/socket.io.min.js"></script>
- <script>
- window.onload = function () {
- // Connect to socket.io
- {# document.domain + ':' + location.port#}
- console.log(location.port);
- socket = io.connect('wss://' + document.domain + ':' + location.port + '/echo');
- document.getElementById("sendBtn").addEventListener('click', function() {
- var cmdVal = document.getElementById("cmd").value;
- var valVal = document.getElementById("value").value;
- socket.emit(cmdVal, { msg: valVal });
- });
- // React to a received message
- socket.on('answer', function (data){
- console.log("data::", data);
- document.getElementById("console").innerHTML = data.message;
- console.log(data);
- });
- socket.on('connect', function (){
- socket.emit('{ "action" : "/questions", "data":{} }');
- });
- socket.on('ping', function (data) {
- // Modify the DOM to show the message
- document.getElementById("msg").innerHTML = data.msg;
- // Send a message back to the server
- socket.emit('pong', {
- msg: "The web browser also knows socket.io."
- });
- });
- };
- </script>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement