I have just started learning about WebSocket recently. On http://www.websocket.org/ it is mentioned that:
A WebSocket connection is established by upgrading from the HTTP protocol to the WebSockets protocol during the initial handshake between the client and the server.
And earlier on the page:
To connect to an end-point, just create a new WebSocket instance, providing the new object with a URL that represents the end-point to which you wish to connect, as shown in the following example. Note that a ws:// and wss:// prefix are proposed to indicate a WebSocket and a secure WebSocket connection, respectively.
var myWebSocket = new WebSocket("ws://www.websockets.org");
My question is: why do I need to include "ws" or "wss" in the URL when the HTTP server knows that it should upgrade the protocol?
I have gone through a few tutorials. In all of them the URL argument to the WebSocket constructor is the same as the HTTP server URL. Is it because we first establish connection to that URL and then the WebSocket is bound to that connection? I am a newbie on this. Some clear explanation will be highly appreciated regarding this.
Just like you need to specify http://
or https://
to tell the browser whether to use SSL with HTTP, you need ws://
or wss://
to let it know whether to use SSL with WebSockets.