Guest User

Untitled

a guest
Jul 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. var socket;
  2. socket = new WebSocket(host);
  3. socket.onopen = function(msg){
  4. // process onopen
  5. };
  6. socket.onmessage = function(msg){
  7. // process message
  8. };
  9. socket.close = function(msg){
  10. // process close
  11. };
  12.  
  13. function dohandshake($user,$buffer){
  14. // getheaders and calcKey are confirmed working, can provide source if desired
  15. list($resource,$host,$origin,$key,$version) = $this->getheaders($buffer);
  16. $request = "HTTP/1.1 101 Switching Protocolsrn" .
  17. "Upgrade: WebSocketrn" .
  18. "Connection: Upgradern" .
  19. "Sec-WebSocket-Accept: " . $this->calcKey($key) . "rn";
  20. socket_write($user->socket,$request);
  21. $user->handshake=true;
  22. return true;
  23. }
  24.  
  25. function dohandshake($user,$buffer){
  26. // getheaders and calcKey are confirmed working, can provide source if desired
  27. list($resource,$host,$origin,$key,$version) = $this->getheaders($buffer);
  28. $request = "HTTP/1.1 101 Switching Protocolsrn" .
  29. "Upgrade: WebSocketrn" .
  30. "Connection: Upgradern" .
  31. "Sec-WebSocket-Accept: " . $this->calcKey($key) . "rnrn";
  32. socket_write($user->socket,$request);
  33. $user->handshake=true;
  34. return true;
  35. }
  36.  
  37. function calcKey($key){
  38. $CRAZY = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
  39. $sha = sha1($key.$CRAZY,true);
  40. return base64_encode($sha);
  41. }
Add Comment
Please, Sign In to add comment