I executed web socket with drawing by using below source https://github.com/kallaspriit/PHP-HTML5-WebSocket-Server
I was able to run the script which works in FF and chrome browsers but does not in safari. As far as I know this might be related to handshake that is being used in safari ( different than in FF and chrome).
In class SocketServer.php I found below rule :
$headers = $this->parseRequestHeader($buffer);
if (isset($headers['Sec-WebSocket-Key'])) {
$key = $headers['Sec-WebSocket-Key'];
} else {
$key = $headers['Sec-WebSocket-Key1'];
}
$hash = base64_encode(
sha1($key . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11', true)
);
/ in ff and chrome in header exist Sec-WebSocket-Key, and safari has Sec-WebSocket-Key1 and Sec-WebSocket-Key2 /
if (isset($headers['Sec-WebSocket-Key'])) {
$headers = array(
'HTTP/1.1 101 Switching Protocols',
'Upgrade: websocket',
'Connection: Upgrade',
'Sec-WebSocket-Accept: ' . $hash
);
} else {
$headers = array(
"HTTP/1.1 101 Web Socket Protocol Handshake",
"Upgrade: WebSocket",
"Connection: Upgrade",
"WebSocket-Origin: http://localhost",
"WebSocket-Location: ws://localhost:9300",
);
}
$headers = implode("\r\n", $headers) . "\r\n\r\n";
$left = strlen($headers);
do {
$sent = @socket_send($this->socket, $headers, $left, 0);
if ($sent === false) {
$error = $this->server->getLastError();
throw new Exception(
'Sending handshake failed: : ' . $error->message .
' [' . $error->code . ']'
);
}
$left -= $sent;
if ($sent > 0) {
$headers = substr($headers, $sent);
}
} while ($left > 0);
$this->state = self::STATE_OPEN;
}
I was trying to change headlines for safari however with no effect. Safari connects me and disconnects in the same time - I think the issue is caused by those headlines and I don't know how to customise them to work in proper way. Does anyone have an idea how to modify code to support safari as well as other browsers?