By example, let's imagine that cluster number 2 already responding to cluster number 1, and onResponse() event is fired in cluster 2:
http://serverONE.com/src/SkynetUser/MyListener.php or http://serverONE.com/skynet1.php (cluster one):
public function onResponse($context)
{
if($context == "beforeSend")
{
/* response to cluster one is creating here */
}
}
As you see, at this moment response for request from cluster 1 is generating.
But what if you want to connect here with another cluster and send request to it? You should use SkynetPeer.
Example:
http://serverTWO.com/src/SkynetUser/MyListener.php or http://serverTWO.com/skynet2.php (cluster two):
use Skynet\Core\SkynetPeer;
use Skynet\Data\SkynetRequest;
public function onResponse($context)
{
if($context == "beforeSend")
{
/* response to cluster one is creating here */
$skynetPeer = new SkynetPeer();
$newRequest = new SkynetRequest();
$newRequest->set('foo', 'bar');
$skynetPeer->assignRequest($newRequest);
$skynetPeer->connect('CLUSTER_THREE_ADDRESS');
}
}
In code above we are creating response to cluster number 1.
In that response SkynetPeer was created, new request was created and the request was sent to cluster number 3.
With this method you can connect with cluster three even when you are actually responding to cluster one.
Note that you can also assign actual $request to SkynetPeer instead of creating new one:
$skynetPeer->assignRequest($this->request);
Code above will assign actual $request (received from cluster 1) and resend this request to cluster 3.