Working with websockets

16

I'm trying to use WebSockets in PHP and Javascript and I'm confused, it uses the ws: // and wss: // protocol and the hostgator ) do not have these protocols enabled (I think!) and I can not connect, does anyone know if I need to enable these protocols on the server or how do I make the connection?

I tried connecting to another server that I found in examples and I ...
Here is the code (with server running):

<script>

var connection = new WebSocket('ws://echo.websocket.org/')

connection.onopen = function(e) {
  alert("Connected");
  console.log("Connected");
};

connection.onclose = function(e) {
  alert("Connection closed");
  console.log("Connection closed");
};

</script>


EDIT: Is it possible to stream audio using websockets?

    
asked by anonymous 05.06.2014 / 21:39

2 answers

2

Well, I still can not post comments = (!

But then check to see if your apache has the proxy_wstunnel module activated, if it is nginx, the first version with the websocket proxy is 1.3.13. The tutorial posted by @ user3230262 is mass, but does not talk about PHP, I recommend you take a look at ratchet .

Finally, pull out only this list of clients and servers that support the html5 websockets api

    
17.06.2014 / 15:53
0

The ws:// and wss:// protocol does not need to be installed or enabled. This protocol is used by the browser to assist in identifying the type of request and to know how to handle the header or body information better when sending or returning the request.

This protocol is new and is available in browsers that support the connection to websocket. It is not mandatory to use this protocol for the connection, but it will make life much easier.

However, it is common to run the server script on a specific port, since 80 is already in use by Apache.

So your address could be ws: // localhost: 8080 / for example.

The stream of audio or video is nothing more than a transmission of small pieces of files between the client to server and vice versa. So, just create a websocket that receives and transmits the data received to the clients.

    
29.09.2014 / 07:38