I have a PHP site that generates some HTML and Javascript. The Javascript initializes a Websocket and sends a message to the server after onopen fires. It works locally, but over the internet the connection is never established.
I'm trying to pin down the error. I have connected via websocket to my server across the internet from a plain html site with Javascript before. Is there any security mechanism against websockets in PHP sites or something? Here's the code briefly, can't see why it shouldn't work (especially since it works locally):
<?php
echo "<!DOCTYPE html>
<html>
<head>
<script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js\"></script>
<script>window.jQuery || document.write('<script src=\"js/vendor/jquery-1.11.0.min.js\"><\/script>');</script>
</head>
<body>
<script>
var socket;
var host = \"ws://xx.xxx.xx.xxx:1237/websocket\";
$(document).ready(function()
{
connect();
});
function connect()
{
socket = new WebSocket(host);
socket.onopen = function()
{
// never fires
};
}
</script>
</body>
</html>";
?>