test.html 995 B

123456789101112131415161718192021222324252627282930313233343536
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>twspy echo test client</title>
  5. </head>
  6. <body>
  7. <textarea id="log" rows="20" cols="80" readonly="readonly"></textarea>
  8. <script type="text/javascript">
  9. function log(line) {
  10. document.getElementById('log').innerHTML += line + '\n';
  11. }
  12. var URL = 'localhost:8000';
  13. log('Connecting to ' + URL);
  14. var ws = new WebSocket('ws://' + URL);
  15. ws.onopen = function() {
  16. log('Connection complete, sending "foo"');
  17. ws.send('foo');
  18. };
  19. ws.onmessage = function(msg) {
  20. log('Received "' + msg + '", closing connection');
  21. ws.close();
  22. };
  23. ws.onerror = function(e) {
  24. log('Error', e);
  25. };
  26. ws.onclose = function() {
  27. log('Connection closed');
  28. };
  29. </script>
  30. </body>
  31. </html>