WebSocket on localhost does not establish connection

0

I'm testing WebSocket running on port 80 , I've disabled SSL , but I'm not getting results ...

javascript

 var ws = new WebSocket('ws://localhost:80/socket2.php');

One example I saw, tested, and returned successfully was using wss://echo.websocket.org . So I guess the error is right here. The return of the browser is always the same:

  

Firefox was unable to establish a connection to the server ws: //localhost/socket2.php

Headers as in example :

socket2.php

header("HTTP/1.1 101 Switching Protocols");

header("Upgrade: websocket");
header("Connection: Upgrade");
header("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=");

In the console the WebSocket request returns 101 / websocket / 0B

Apache , it's all as before.

    
asked by anonymous 23.05.2018 / 01:14

1 answer

0

The server has to stay on a port other than apache, by default it comes at 80, if your apache is at 80, change the server port to 8080 for example so there is no conflict, I think this should work.

    
26.06.2018 / 23:55