Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call $this->receive() twice in Connection::connect() #57

Closed
dfeyer opened this issue Jun 10, 2016 · 4 comments
Closed

Call $this->receive() twice in Connection::connect() #57

dfeyer opened this issue Jun 10, 2016 · 4 comments
Assignees

Comments

@dfeyer
Copy link
Contributor

dfeyer commented Jun 10, 2016

Maybe my misunderstanding of the Nats protocol, but why did we call $this->receive(); twice in Connection::connect() ?

public function connect($timeout = null)
{
    $this->timeout = $timeout;
    $this->streamSocket = $this->getStream($this->options->getAddress(), $timeout);
    $msg = 'CONNECT '.$this->options;
    $this->send($msg);

    $response = $this->receive();

    $this->ping();
    $response = $this->receive();

    if ($response !== "PONG") {
        if (strpos($response, '-ERR')!== false) {
            throw new \Exception("Failing connection: $response");
        }
    }
}
@repejota repejota self-assigned this Jun 15, 2016
@dfeyer
Copy link
Contributor Author

dfeyer commented Jun 16, 2016

Can this one related to #58 ?

@repejota
Copy link
Owner

No it is not related.
I made this as i was expecting INFO after a connect ( http://nats.io/documentation/internals/nats-protocol/#description:4b9a176fc3df6b183e7b5ba0c60737ef)

Then i am sending a PING so i need to receive a PONG. That's why i have two receives.

Not sure if this is the correct way, but I will test it carefully once i finish the new test suite on #60
Gonna be soon 😉

Did you found any problems with this behaviour?

@dfeyer
Copy link
Contributor Author

dfeyer commented Jun 16, 2016

Did you found any problems with this behaviour?

Not directly, but by reading it sounds a bit strange. But protocol wise it sounds OK. Maybe we can just skip the creation of the first $response variable (not used, so no needs, a bit a micro optimisation), and add a small comment to help other people looking at this.

@repejota
Copy link
Owner

Sounds good.
I will leave this open to work on it after i finish #60

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants