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.

index.html 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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('http://' + document.domain + ':' + location.port);
  8. function sendMessage() {
  9. var message = document.getElementById('message').value;
  10. socket.emit('message', message);
  11. }
  12. socket.on('connect', function () {
  13. console.log('Connected to the server');
  14. socket.emit('message', "run_fn");
  15. });
  16. socket.on('response', function (data) {
  17. console.log('Server says: ' + data);
  18. });
  19. clog=console.log
  20. function rec_q_to_tab(data_str,a,b,c,d){
  21. clog({that:this},arguments)
  22. var data = JSON.parse(data_str)
  23. clog(data)
  24. lines = data.file_content.split("\n")
  25. proc_data = {arr:[]}
  26. for (line of lines){
  27. if (!line){
  28. clog("NOT LINE",line)
  29. continue
  30. }
  31. // clog()
  32. proc_data.arr.push(JSON.parse(line))
  33. }
  34. }
  35. socket.on('q_to_tab_q', rec_q_to_tab)
  36. </script>
  37. </head>
  38. <body>
  39. <h1>WebSocket Example</h1>
  40. <input type="text" id="message" placeholder="Type a message">
  41. <button onclick="sendMessage()">Send</button>
  42. </body>
  43. </html>