sannremy/PHP-Push-WebSocket

Error when browser refresh

grillorafael opened this issue · 2 comments

Hey, everytime I refresh my browser I get this error message:

socket_shutdown(): unable to shutdown socket [57]: Socket is not connected.

Any idea?

You have to check if the bin2hex() value of the unmasked data is equal to 03e9, that solved it for me. I made the following checks which appear to work for me:

if ($data === false) {
    $this->__disconnect($client, 'Client data equal to "false"');
}
# if the socket_read returns false, disconnect the client
elseif ($data === null) {
    $this->__disconnect($client, 'Client data equal to "null"');
}
elseif (empty($data)) {
    $this->__disconnect($client, 'Client data empty, we assume it is disconnected');
}
# if no handshake is made yet, make one
elseif (!$client->getHandshake()) {
    if (!$this->__handshake($client, $data)) {
        $this->__disconnect($client, 'Could not make handshake');
    }
}
elseif (bin2hex($unmasked = $this->__unmask($data)) == 03e9) {
    $this->__disconnect($client, 'Unmasked client data equal to "03e9"');
}
# We have "valid" data to do stuff with
else {
    $this->__action($client, $unmasked);
}

please not that I changed some method names in order to match the CakePHP conventions, so simply copy-pasting won't do ;-)

I will make the change :)
Thanks!