If your web server supports WebSockets (or the WebSocket handler module), you can use the same host and port and just change the scheme as you show. There are many possibilities for starting a web server and a Websocket server / module.
I would suggest that you look at the individual parts of window.location global and put them together instead of doing blind line replacements.
var loc = window.location, new_uri; if (loc.protocol === "https:") { new_uri = "wss:"; } else { new_uri = "ws:"; } new_uri += "//" + loc.host; new_uri += loc.pathname + "/to/ws";
Note that some web servers (such as those associated with Jetty) currently use the path (rather than the update header) to determine if a particular request should be passed to the WebSocket handler. That way, you can be limited to whether you can transform the path the way you want.
kanaka May 2 '12 at 16:39 2012-05-02 16:39
source share