Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Websocket pod safari, zmiana hederów
pablo_83
post
Post #1





Grupa: Zarejestrowani
Postów: 200
Pomógł: 16
Dołączył: 11.01.2009
Skąd: wrocław

Ostrzeżenie: (0%)
-----


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?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
wNogachSpisz
post
Post #2





Grupa: Zarejestrowani
Postów: 1 233
Pomógł: 87
Dołączył: 6.03.2009

Ostrzeżenie: (40%)
XX---


Zajefajny soft, dużego gość ma skilla w php i js.
Ciekawe jak długo to pisał.

Ten post edytował wNogachSpisz 10.12.2012, 12:05:14
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 08:20