Kraken Ipc is a component that aims to provide asynchronous IPC models for your application.
Right now Kraken IPC supports:
- TCP sockets,
- UNIX sockets,
- ZMQ sockets and their subprotocols.
class Socket implements SocketInterface
interface SocketInterface extends AsyncStreamInterface
SocketInterface::getLocalEndpoint() : string
Get local endpoint matching following pattern [protocol://address:port].
SocketInterface::getRemoteEndpoint() : string
Get remote endpoint matching following pattern [protocol://host:port].
SocketInterface::getLocalAddress() : string
Get local address matching following pattern [host:port].
SocketInterface::getRemoteAddress() : string
Get remote address matching following pattern [host:port].
SocketInterface::getLocalPort() : string
Get local host.
SocketInterface::getRemotePort() : string
Get remote host.
SocketInterface::getLocalPort() : string
Get local port.
SocketInterface::getRemotePort() : string
Get remote port.
class SocketListener extends BaseEventEmitter implements SocketListenerInterface
/**
* @event connect : callable(object, SocketInterface)
*/
interface SocketListenerInterface extends EventEmitterInterface, LoopResourceInterface, StreamBaseInterface
SocketListenerInterface::getLocalEndpoint() : string
Get local endpoint matching following pattern [protocol://address:port].
SocketListenerInterface::getLocalAddress() : string
Get local address matching following pattern [host:port].
SocketListenerInterface::getLocalPort() : string
Get local host.
SocketListenerInterface::getLocalPort() : string
Get local port.
$server = new SocketListener($endpoint, $loop);
$server->on('connect', function(SocketListenerInterface $server, SocketInterface $conn) {
$conn->on('data', function(SocketInterface $conn, $data) use($server) {
$conn->write('secret answer!');
$server->close();
});
});
$client = new Socket($endpoint, $loop);
$client->on('data', function(SocketInterface $conn, $data) {
echo "Received answer=$data\n";
$conn->close();
});
$client->write('secret question!');