amphp / websocket-client

Async WebSocket client for PHP based on Amp.
https://amphp.org/websocket-client
MIT License
147 stars 17 forks source link

Call to undefined method Amp\Coroutine::receive() #48

Closed mnapoli closed 10 months ago

mnapoli commented 1 year ago

I tried the example from the README and I'm getting an error on the receive() call:

Call to undefined method Amp\Coroutine::receive()

<?php

require 'vendor/autoload.php';

use Amp\Websocket\Client;

$connection = Client\connect('ws://localhost:1337/ws');

while ($message = $connection->receive()) {
    $payload = $message->buffer();

    printf("Received: %s\n", $payload);

    if ($payload === '100') {
        $connection->close();
        break;
    }
}

Am I missing something obvious?

bwoebi commented 1 year ago

This suspiciously sounds like you've checked out 1.x instead of 2.x?

mnapoli commented 1 year ago

Oh right… there's no stable 2.x. Should I go with 2.x still? Is the website documentation targeting 2.x?

(I'm new with Amp, I'm looking at the simplest onboarding possible 😅)

kelunik commented 1 year ago

Yes, use the library versions compatible with Amp v3.

mnapoli commented 1 year ago

Well v1 installed Amp v3 but is that what you are saying?

kelunik commented 1 year ago

V1 should install Amp v2, v2 should install Amp v3.

bwoebi commented 10 months ago

We now have a stable 2.0.0 release, so I guess we can close this :-)