var websocket = new WebSocket( 'ws://ec2-177-71-x-x.sa-east-1.compute.amazonaws.com:60997');
Вот запрос в Firefox консоль:
Код: Выделить всё
Host: ec2-177-71-x-x.sa-east-1.compute.amazonaws.com:60997
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:26.0) Gecko/20100101 Firefox/26.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Sec-WebSocket-Version: 13
Origin: http://localhost
Sec-WebSocket-Key: csxgGFmTuJYxgvfsbgKtyA==
Connection: keep-alive, Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Код: Выделить всё
Connection: "Upgrade"
Sec-WebSocket-Accept: "AmwLLFdVkE9buCccH1oggz4FNJM="
Upgrade: "websocket"
WebSocket-Location: "ws://ec2-177-71-x-x.sa-east-1.compute.amazonaws.com:60997"
WebSocket-Origin: "ec2-177-71-x-x.sa-east-1.compute.amazonaws.com"
Думаю, проблема может быть в рукопожатии, вот функцию, которую я использую
Код: Выделить всё
//handshake new client.
function perform_handshaking($receved_header,$client_conn, $host, $port)
{
var_dump($receved_header);
$headers = array();
$lines = preg_split("/\r\n/", $receved_header);
foreach($lines as $line)
{
$line = chop($line);
if(preg_match('/\A(\S+): (.*)\z/', $line, $matches))
{
$headers[$matches[1]] = $matches[2];
}
}
$secKey = $headers['Sec-WebSocket-Key'];
$secAccept = base64_encode(pack('H*', sha1($secKey . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')));
//hand shaking header
$upgrade = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" .
"Upgrade: websocket\r\n" .
"Connection: Upgrade\r\n" .
"WebSocket-Origin: $host\r\n" .
"WebSocket-Location: ws://$host:$port\r\n".
"Sec-WebSocket-Accept:$secAccept\r\n\r\n";
var_dump(socket_write($client_conn,$upgrade,strlen($upgrade)));
}
Версия PHP на рабочем сервере, где возникает проблема: PHP 5.3.27
Подробнее здесь: https://stackoverflow.com/questions/254 ... -in-chrome
Мобильная версия