1

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?

pablo
  • 21
  • 3
  • In whcih vesrion you can see discussion http://stackoverflow.com/questions/1253683/what-browsers-support-html5-websocket-api here – Anup Yadav Dec 11 '12 at 10:33

1 Answers1

0

It looks like the WebSocket server hasn't been updated in 9 month. So, I'd recommend you look at an alternative PHP WebSocket solution such as Ratchet which is actively being developed.

leggetter
  • 15,248
  • 1
  • 55
  • 61