WebSocket SyntaxError: Invalid or illegal string specified

I get SyntaxError: An invalid or illegal string was specifiedtrying to connect to a WebSocket in Firefox.

<!doctype html>
<html>
  <head><meta charset="utf-8"></head>
  <body>
    <script>
    var socket = new WebSocket('127.0.0.1:1234');
    </script>
  </body>
</html>

Why am I getting this error?

+4
source share
1 answer

It seems like a schema is required when trying to connect to a WebSocket, so this is:

var socket = new WebSocket('ws://127.0.0.1:1234');

works great.

+9
source

Source: https://habr.com/ru/post/1624403/


All Articles