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

Connection closed #31

Closed
nekulin opened this issue Aug 10, 2016 · 6 comments
Closed

Connection closed #31

nekulin opened this issue Aug 10, 2016 · 6 comments

Comments

@nekulin
Copy link

nekulin commented Aug 10, 2016

$loop = \React\EventLoop\Factory::create();
$factory = new Factory($loop);
$factory->createClient($target)->then(
    function (Client $client) use ($loop) {
    echo 'Client connected ' . PHP_EOL;
    $sender = new ActionSender($client);
    $sender->events(true);
    $client->on('close', function() {
        echo 'Connection closed' . PHP_EOL;
    });
    $client->on('event', function (Event $event) {
        echo 'Event: ' . $event->getName() . ': ' . json_encode($event->getFields()) . PHP_EOL;
    });
    },
    function (\Exception $error) {
    echo 'Connection error: ' . $error;
    }
);
$loop->run();

Perform and immediately closes the connection:

Client connected
Connection closed

@nekulin
Copy link
Author

nekulin commented Aug 10, 2016

$loop = \React\EventLoop\Factory::create();
$factory = new Factory($loop);
$factory->createClient($target)->then(
    function (Client $client) use ($loop) {
    echo 'Client connected ' . PHP_EOL;

    $client->on('close', function() {
        echo 'Connection closed' . PHP_EOL;
    });
    $client->on('event', function (Event $event) {
        //echo 'Event: ' . $event->getName() . ': ' . json_encode($event->getFields()) . PHP_EOL;
    });
    },
    function (\Exception $error) {
    echo 'Connection error: ' . $error;
    }
);
$loop->run();

It works, but when the event comes, the connection is closed!

@clue
Copy link
Owner

clue commented Aug 10, 2016

Thanks for reporting!

Which Asterisk server version are you connecting to?

You may also want to try adding an error handler like this:

$client->on('error', function (Exception $error) {
    echo $error;
});

@avbdr
Copy link

avbdr commented Oct 25, 2016

Hello,
Thanks for a great library. i got the same problem with asterisk 11.13

event:

Response: Success
ActionID: 2
Events: OnEvent: RTCPSent
Privilege: reporting,all
To: 119.9.36.210:22377
OurSSRC: 33664931
SentNTP: 1477431347.2821844992
SentRTP: 2238640
SentPackets: 11241
SentOctets: 1798560
ReportBlock:
FractionLost: 0
CumulativeLoss: 0
IAJitter: 0.0000
TheirLastSR: 0
DLSR: 53299.6880 (sec)

exception

exception 'UnexpectedValueException' with message 'Parse error, no colon in line "ReportBlock:" found' in /var/www/cc/ws/vendor/clue/ami-react/src/Protocol/Parser.php:56
Stack trace:
#0 /var/www/cc/ws/vendor/clue/ami-react/src/Protocol/Parser.php(35): Clue\React\Ami\Protocol\Parser->parseMessage('Event: RTCPSent...')
#1 /var/www/cc/ws/vendor/clue/ami-react/src/Client.php(36): Clue\React\Ami\Protocol\Parser->push('Event: RTCPSent...')
#2 [internal function]: Clue\React\Ami\Client->Clue\React\Ami\{closure}('Event: RTCPSent...', Object(React\Stream\Stream))
#3 /var/www/cc/ws/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(64): call_user_func_array(Object(Closure), Array)
#4 /var/www/cc/ws/vendor/react/stream/src/Stream.php(133): Evenement\EventEmitter->emit('data', Array)
#5 [internal function]: React\Stream\Stream->handleData(Resource id #70, Object(React\EventLoop\StreamSelectLoop))
#6 /var/www/cc/ws/vendor/react/event-loop/src/StreamSelectLoop.php(232): call_user_func(Array, Resource id #70, Object(React\EventLoop\StreamSelectLoop))
#7 /var/www/cc/ws/vendor/react/event-loop/src/StreamSelectLoop.php(201): React\EventLoop\StreamSelectLoop->waitForStreamActivity(NULL)
#8 /var/www/cc/ws/ws.php(286): React\EventLoop\StreamSelectLoop->run()
#9 {main}

@clue
Copy link
Owner

clue commented Nov 1, 2016

Thanks for reporting this @avbdr! This has already been fixed via #29, I've only just now tagged a new v0.3.1 release, so this should no longer occur 👍

@clue clue closed this as completed Nov 1, 2016
@mariapaulinar
Copy link

mariapaulinar commented May 26, 2017

When I use this package to get ami events and I invoke it using the Laravel dispatcher, it throws me a timeout error. How I can avoid this? I'm new working with reactphp. I appreciate any help or idea :( My code is:
$loop = \React\EventLoop\Factory::create();
$factory = new Factory($loop);
$target = 'admin:123456@192.168.0.6';
$factory->createClient($target)->then(
function (Client $client) {
echo 'Client connected ' . PHP_EOL;
$sender = new ActionSender($client);
$sender->events(true);
$client->on('close', function() {
echo 'Connection closed' . PHP_EOL;
});
$client->on('event', function (Event $event) {
$fields = $event->getFields();
foreach($fields as $k => $f) {
DB::table('eventos_llamada')->insert([
'evento' => $event->getName(),
'campo' => $k,
'valor' => $f,
]);
}
echo 'Evento leido';
});
},
function (Exception $error) {
echo 'Connection error: ' . $error;
}
);
$loop->run();

@clue
Copy link
Owner

clue commented May 28, 2017

@mariapaulinar It looks like this is an unrelated issue, may I ask you to file a new issue instead? Thanks!

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

4 participants