You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

flask_index.html 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>WebSocket Example</title>
  5. <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/3.1.3/socket.io.js"></script>
  6. <script type="text/javascript">
  7. // var socket = io.connect('https://' + document.domain + ':' + location.port);
  8. var socket = io.connect('https://' + "127.0.0.1" + ':' + 5000);
  9. function sendMessage() {
  10. var message = document.getElementById('message').value;
  11. socket.emit('message', message);
  12. }
  13. socket.on('connect', function () {
  14. console.log('Connected to the server');
  15. // socket.emit('message', "run_fn");
  16. });
  17. socket.on('response', function (data) {
  18. console.log('Server says: ' + data);
  19. });
  20. function function_name(argument) {
  21. // body...
  22. }
  23. clog=console.log
  24. function rec_q_to_tab(data_str,a,b,c,d){
  25. clog({that:this},arguments)
  26. var data = JSON.parse(data_str)
  27. clog(data)
  28. lines = data.file_content.split("\n")
  29. proc_data = {arr:[]}
  30. for (line of lines){
  31. if (!line){
  32. clog("NOT LINE",line)
  33. continue
  34. }
  35. // clog()
  36. proc_data.arr.push(JSON.parse(line))
  37. }
  38. }
  39. socket.on('q_to_tab_q', rec_q_to_tab)
  40. </script>
  41. </head>
  42. <body>
  43. <h1>WebSocket Example</h1>
  44. <input type="text" id="message" placeholder="Type a message">
  45. <button onclick="sendMessage()">Send</button>
  46. </body>
  47. </html>