Ratchet icon indicating copy to clipboard operation
Ratchet copied to clipboard

closing connection manually does not trigger onClose

Open Stevemoretz opened this issue 3 years ago • 4 comments

What I've figured out so far

  1. The connection is reported to be closed for client with the same 1010 code, so it actually gets closed and no problem on that side.
  2. If the connection is closed by the client, this function gets triggered without any problems.

The problem

I'm doing something like:

$conn->close(1010);

But this function is not triggered.

    public function onClose( ConnectionInterface $conn ) {
        $this->print("ssss");
        parent::onClose( $conn );
    }

I use that function to cleanUp connection specific data, so it's kind of important. however I can just call it myself, but I need to know is this a bug or is it intended? (to prevent duplication.)

Also using :

        $ws_server->enableKeepAlive($server->loop, 15);

Not sure if that is supposed to help in this case, but it has no effect on this case.

Stevemoretz avatar Jan 16 '22 21:01 Stevemoretz

I am Facing Same Problem.did you Find any Solution? @Stevemoretz

inder172 avatar Apr 02 '22 22:04 inder172

I am Facing Same Problem.did you Find any Solution? @Stevemoretz

The workaround is to extend the class, override the close method and call onClose in there.

Stevemoretz avatar Apr 03 '22 04:04 Stevemoretz

Can you Please share the Code.

actually I am using enablekeepAlive and it is not Suitable for Large number of websocket Connection

inder172 avatar Apr 06 '22 00:04 inder172

Regarding keep alive that is not necessary nor relevant keep it off.

But You're right my explaining was insufficient, actually it has one more step, you need to create a client wrapper, also you need to put your ratchet server instance in a container or global variable, once you call the close on your client wrapper you need to access the global variable and call onClose in there manually. (of course use your client wrapper in the subclass that extends the main ratchet class)

I can't share my code because it has a lot of dependency subclasses it would be harder to Understand, but that's the way it works under the hood, if you have any further questions feel free to ask.

Stevemoretz avatar Apr 06 '22 05:04 Stevemoretz