Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var socket;
- socket = new WebSocket(host);
- socket.onopen = function(msg){
- // process onopen
- };
- socket.onmessage = function(msg){
- // process message
- };
- socket.close = function(msg){
- // process close
- };
- function dohandshake($user,$buffer){
- // getheaders and calcKey are confirmed working, can provide source if desired
- list($resource,$host,$origin,$key,$version) = $this->getheaders($buffer);
- $request = "HTTP/1.1 101 Switching Protocolsrn" .
- "Upgrade: WebSocketrn" .
- "Connection: Upgradern" .
- "Sec-WebSocket-Accept: " . $this->calcKey($key) . "rn";
- socket_write($user->socket,$request);
- $user->handshake=true;
- return true;
- }
- function dohandshake($user,$buffer){
- // getheaders and calcKey are confirmed working, can provide source if desired
- list($resource,$host,$origin,$key,$version) = $this->getheaders($buffer);
- $request = "HTTP/1.1 101 Switching Protocolsrn" .
- "Upgrade: WebSocketrn" .
- "Connection: Upgradern" .
- "Sec-WebSocket-Accept: " . $this->calcKey($key) . "rnrn";
- socket_write($user->socket,$request);
- $user->handshake=true;
- return true;
- }
- function calcKey($key){
- $CRAZY = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
- $sha = sha1($key.$CRAZY,true);
- return base64_encode($sha);
- }
Add Comment
Please, Sign In to add comment