Git Product home page Git Product logo

Comments (4)

morozovsk avatar morozovsk commented on July 1, 2024

Thank you very much for your feedback. You did a really deep code analysis and found there are some problems.

if ($this->_handshakes[$connectionId]) {//если уже было получено рукопожатие от клиента
    return;//то до отправки ответа от сервера читать здесь пока ничего не надо
}

This code is never executed because the $this->_handshakes[$connectionId] contains an empty string ('') which evaluates to false not true. I will remove this code.

if (!$this->_handshake($connectionId)) {
    $this->close($connectionId);
}

You made a mistake. This code close connection only if all headers received:

if (!strpos($this->_read[$connectionId], "\r\n\r\n")) {
    return true;
}
if ($write) {
    foreach ($write as $client) {
      if (is_resource($client)) {//проверяем, что мы его ещё не закрыли во время чтения
        $this->_sendBuffer($client);
        if ($this->_handshakes[$client] == false) { $this->close($client); }
      }
    }
  }

This code is not enough to send the data from the buffer to the client, you must also make sure that the data is completely gone, and the buffer is empty.
I will fix it in the next version.

  1. I will translate all comments to English :)

Thank you again for your review.

from websocket.

sebstyle avatar sebstyle commented on July 1, 2024

You were right, that empty string does evaluate to false :)
Also, keep in mind that until handshake is returned to client you would have to redirect normal messages to a separate buffer that gets written once the handshake is completed.
Otherwise the write buffer may contain a message before it contains the handshake reply.
This is why so many websocket classes maintain a client object to keep track of such things.

from websocket.

morozovsk avatar morozovsk commented on July 1, 2024

Daemon.php:

protected function sendToClient($connectionId, $data, $type = 'text') {
        if (!isset($this->_handshakes[$connectionId])) {
            $this->_write($connectionId, $this->_encode($data, $type));
        }
    }

until I do not finish a handshake with the client all messages ignored

from websocket.

sebstyle avatar sebstyle commented on July 1, 2024

Then it was a logic error on my behalf :)
I do apologize for that..
Latest websocket specs also no longer mentions http error codes so i guess all is good.

I am having some problems implementing status codes in the close frame as per the latest specs.
Is there any way i can contact you about this issue?
Perhaps we can work together towards a solution that will also work in your project..
You can send an email to the info@ the website address domain specified in my profile.

Thanks in advance!

from websocket.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.