Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Websocket pod safari, zmiana hederów
Forum PHP.pl > Forum > PHP
pablo_83
Witam, uruchomiłem u siebie websocket z rysowaniem online korzystając z źródła https://github.com/kallaspriit/PHP-HTML5-WebSocket-Server

Udało mi się uruchomić skrypt i działa mi on pod przeglądarkami ff i chrome, a nie działa pod safari. Z tego co wyczytałem chodzi o handshake jaki jest obsługiwany pod safari. Jest on inny niż pod chromem i ff.

w class SocketServer.php jest metoda:
  1. public function performHandshake($buffer) {
  2. if ($this->state != self::STATE_CONNECTING) {
  3. throw new Exception( 'Unable to perform handshake, client is not in connecting state' );
  4. }
  5.  
  6. $headers = $this->parseRequestHeader($buffer);
  7.  
  8. if (isset($headers['Sec-WebSocket-Key'])) {
  9. $key = $headers['Sec-WebSocket-Key'];
  10. } else {
  11. $key = $headers['Sec-WebSocket-Key1'];
  12. }
  13. $hash = base64_encode(
  14. sha1($key . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11', true)
  15. );
  16. /* in ff and chrome in header exist Sec-WebSocket-Key, and safari has Sec-WebSocket-Key1 and Sec-WebSocket-Key2 */
  17.  
  18. if (isset($headers['Sec-WebSocket-Key'])) {
  19. $headers = array(
  20. 'HTTP/1.1 101 Switching Protocols',
  21. 'Upgrade: websocket',
  22. 'Connection: Upgrade',
  23. 'Sec-WebSocket-Accept: ' . $hash
  24. );
  25. } else {
  26. $headers = array(
  27. "HTTP/1.1 101 Web Socket Protocol Handshake",
  28. "Upgrade: WebSocket",
  29. "Connection: Upgrade",
  30. "WebSocket-Origin: <a href="http://localhost&quot;" target="_blank">http://localhost"</a>,
  31. "WebSocket-Location: ws://localhost:9300",
  32. );
  33. }
  34.  
  35. $headers = implode("\r\n", $headers) . "\r\n\r\n";
  36. $left = strlen($headers);
  37.  
  38. do {
  39. $sent = @socket_send($this->socket, $headers, $left, 0);
  40.  
  41. if ($sent === false) {
  42. $error = $this->server->getLastError();
  43.  
  44. throw new Exception(
  45. 'Sending handshake failed: : ' . $error->message .
  46. ' [' . $error->code . ']'
  47. );
  48. }
  49.  
  50. $left -= $sent;
  51.  
  52. if ($sent > 0) {
  53. $headers = substr($headers, $sent);
  54. }
  55. } while ($left > 0);
  56.  
  57. $this->state = self::STATE_OPEN;
  58. }

Próbowałem zmieniać nagłówki dla safari, ale bez żadnego efektu. Pod Safari łączy mnie i od razu rozłącza. Problem jak myślę tkwi w tych nagłówkach. Nie wiem jak je dostosować aby także pod safari działało poprawnie. Ma ktoś pomysł jak zmodyfikować kod aby obsługiwał także safari?
wNogachSpisz
Zajefajny soft, dużego gość ma skilla w php i js.
Ciekawe jak długo to pisał.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.