PHP and Javascript WebSocket Confusion -
i have been looking on tutorials websockets, i'm confused how reply handshake.
i've got code:
    protected function handshake($data, $socket) {         $lines = preg_split("/\r\n/", $data);         $headers = array();         if(!preg_match('/\aget (\s+) http\/1.1\z/', $lines[0], $matches)) {              return;         }         $path = $matches[1];         foreach($lines $line){             $line = chop($line);             if(preg_match('/\a(\s+): (.*)\z/', $line, $matches))             {                  $headers[$matches[1]] = $matches[2];             }         }         $seckey = $headers['sec-websocket-key'];         $secaccept = base64_encode(pack('h*', sha1($seckey . '258eafa5-e914-47da-95ca-c5ab0dc85b11')));         $response = "http/1.1 101 switching protocols\r\n";         $response.= "upgrade: websocket\r\n";         $response.= "connection: upgrade\r\n";         $response.= "sec-websocket-accept: " . $secaccept . "";         $this->send($response);   } everything being sent. receiving handshake , sending server. there wrong websocket response? should add something?
here's code:
    <script>     var ws = new websocket('ws://127.0.0.1:6112/');     ws.onopen = function() {         alert('connected');         ws.send('hello!!!!!!1');     };     ws.onmessage = function() {         console.log('new message...');     };     send = function() {         ws.send('some message...');     } </script> can help?
i listening port 6112. sending handshake 6112.
 
 
  
Comments
Post a Comment