I'm using reactphp to create a client for an api server. But i have a problem, when my connection close, whatever the reason, i can't reconnect automatically.
It doesn't work:
$this->loop = \React\EventLoop\Factory::create();
$host = config('app.reactphp_receiver_host');
$port = config('app.reactphp_receiver_port');
$this->connector = new \React\Socket\Connector($this->loop);
$this->connector
->connect(sprintf('%s:%s', $host, $port))
->then(
function (\React\Socket\ConnectionInterface $conn)
{
$conn->on('data', function($data)
{
});
$conn->on('close', function()
{
echo "close\n";
$this->loop->addTimer(4.0, function () {
$this->connector
->connect('127.0.0.1:8061')
->then( function (\Exception $e)
{
echo $e;
});
});
});
});
$this->loop->run();
Exception is empty.