Initial commit
This commit is contained in:
23
examples/jsonprotostream.php
Normal file
23
examples/jsonprotostream.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__."/../vendor/autoload.php";
|
||||
|
||||
use NoccyLabs\React\Protocol\Json\JsonProtocol;
|
||||
use NoccyLabs\React\Protocol\ProtocolStream;
|
||||
use React\Stream\CompositeStream;
|
||||
use React\Stream\ThroughStream;
|
||||
use React\Stream\WritableResourceStream;
|
||||
|
||||
$rs = new ThroughStream();
|
||||
$ws = new WritableResourceStream(STDOUT);
|
||||
$stream = new CompositeStream($rs,$ws);
|
||||
|
||||
$proto = new JsonProtocol(
|
||||
frameSeparator: "\n",
|
||||
prependSizeBytes: 0,
|
||||
);
|
||||
$stream = new ProtocolStream($stream, $proto);
|
||||
|
||||
$stream->send([ 'hello' => 'world' ]);
|
||||
$stream->send([ 'foo' => 'bar', 'answer' => 42 ]);
|
||||
|
||||
Reference in New Issue
Block a user