Skip to content

Commit

Permalink
Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sirn-se committed Nov 27, 2020
1 parent 4409b1d commit 264ad4f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 16 deletions.
15 changes: 7 additions & 8 deletions examples/random_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@

error_reporting(-1);

function randStr(int $maxlength = 4096)
{
$randStr = function (int $maxlength = 4096) {
$string = '';
$length = rand(1, $maxlength);
for ($i = 0; $i < $length; $i++) {
$string .= chr(rand(33, 126));
}
return $string;
}
};

echo "> Random client\n";

Expand Down Expand Up @@ -60,23 +59,23 @@ function randStr(int $maxlength = 4096)
switch (rand(1, 10)) {
case 1:
echo "> Sending text\n";
$client->send('Text message ' . randStr(), 'text');
$client->send("Text message {$randStr()}", 'text');
break;
case 2:
echo "> Sending binary\n";
$client->send('Binary message ' . randStr(), 'binary');
$client->send("Binary message {$randStr()}", 'binary');
break;
case 3:
echo "> Sending close\n";
$client->close(rand(1000, 2000), 'Close message ' . randStr(8));
$client->close(rand(1000, 2000), "Close message {$randStr(8)}");
break;
case 4:
echo "> Sending ping\n";
$client->send('Ping message ' . randStr(8), 'ping');
$client->send("Ping message {$randStr(8)}", 'ping');
break;
case 5:
echo "> Sending pong\n";
$client->send('Pong message ' . randStr(8), 'pong');
$client->send("Pong message {$randStr(8)}", 'pong');
break;
default:
echo "> Receiving\n";
Expand Down
15 changes: 7 additions & 8 deletions examples/random_server.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@

error_reporting(-1);

function randStr(int $maxlength = 4096)
{
$randStr = function (int $maxlength = 4096) {
$string = '';
$length = rand(1, $maxlength);
for ($i = 0; $i < $length; $i++) {
$string .= chr(rand(33, 126));
}
return $string;
}
};

echo "> Random server\n";

Expand Down Expand Up @@ -60,23 +59,23 @@ function randStr(int $maxlength = 4096)
switch (rand(1, 10)) {
case 1:
echo "> Sending text\n";
$server->send('Text message ' . randStr(), 'text');
$server->send("Text message {$randStr()}", 'text');
break;
case 2:
echo "> Sending binary\n";
$server->send('Binary message ' . randStr(), 'binary');
$server->send("Binary message {$randStr()}", 'binary');
break;
case 3:
echo "> Sending close\n";
$server->close(rand(1000, 2000), 'Close message ' . randStr(8));
$server->close(rand(1000, 2000), "Close message {$randStr(8)}");
break;
case 4:
echo "> Sending ping\n";
$server->send('Ping message ' . randStr(8), 'ping');
$server->send("Ping message {$randStr(8)}", 'ping');
break;
case 5:
echo "> Sending pong\n";
$server->send('Pong message ' . randStr(8), 'pong');
$server->send("Pong message {$randStr(8)}", 'pong');
break;
default:
echo "> Receiving\n";
Expand Down
7 changes: 7 additions & 0 deletions tests/scripts/receive-broken-read.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
],
"return":true
},
{
"function": "get_resource_type",
"params": [
"@mock-stream"
],
"return": "stream"
},
{
"function": "stream_get_meta_data",
"params": [
Expand Down
7 changes: 7 additions & 0 deletions tests/scripts/receive-empty-read.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
],
"return":true
},
{
"function": "get_resource_type",
"params": [
"@mock-stream"
],
"return": "stream"
},
{
"function": "stream_get_meta_data",
"params": [
Expand Down
7 changes: 7 additions & 0 deletions tests/scripts/send-broken-write.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
"params": [],
"return": true
},
{
"function": "get_resource_type",
"params": [
"@mock-stream"
],
"return": "stream"
},
{
"function": "stream_get_meta_data",
"params": [
Expand Down
7 changes: 7 additions & 0 deletions tests/scripts/send-failed-write.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
"params": [],
"return": true
},
{
"function": "get_resource_type",
"params": [
"@mock-stream"
],
"return": "stream"
},
{
"function": "stream_get_meta_data",
"params": [
Expand Down

0 comments on commit 264ad4f

Please sign in to comment.