Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebSocket SyntaxError: An invalid or illegal string was specified

I'm getting a SyntaxError: An invalid or illegal string was specified, while trying to connect to a WebSocket on 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 do I get this error?

like image 216
evuez Avatar asked Jan 15 '16 08:01

evuez


1 Answers

It seems like the scheme is mandatory when trying to connect to a WebSocket, so this:

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

works just fine.

like image 191
evuez Avatar answered Sep 22 '22 17:09

evuez