Releases: YGGverse/nps-php
1.3.1
Correction release, includes:
Full Changelog: 1.3.0...1.3.1
1.3.0
New methods
Server::setWelcome
Define application logic on peer connection established
$server->setWelcome(
function (
string $connect
): ?string
{
printf(
"connected: %s\n\r",
$connect
);
return sprintf(
"welcome, %s\n\r",
$connect
);
}
);
Server::getWelcome
Get current Welcome
function, null
by default
Server::setPending
Define application logic on peer make initial request
$server->setPending(
function (
string $request,
string $connect
): ?string
{
printf(
'connection: %s requested: %s',
$connect,
$request,
);
return sprintf(
'received: %s',
$request
);
}
);
Server::getPending
Get current Pending
function, null
by default
Server::setHandler
Define basic application logic on complete packet received
- could be also defined as Server::start argument
$server->setHandler(
function (
bool $success,
string $content,
string $request,
string $connect
): ?string
{
printf(
'connection: %s request: %s',
$connect,
$request
);
if ($success)
{
var_dump(
$content
);
}
return 'thank you!';
}
);
Server::getHandler
Get current Handler
function, null
by default
Example
$server->start();
> nc 127.0.0.1 1915
< welcome, 127.0.0.1:38028
> test
< received: test
> 1
> 2
> 3
> .
< thank you!
Full Changelog: 1.2.0...1.3.0
1.2.0
Implemented optional Server response returned by custom handler
$server->start(
function (
bool $success,
string $content,
string $request,
string $connect
): ?string
{
printf(
'connection: %s request: %s',
$connect,
$request
);
if ($success)
{
var_dump(
$content
);
}
return 'thank you!'; // null|string response
}
);
Full Changelog: 1.1.0...1.2.0
1.1.0
Server
API changed with new features
Now constructor accepts line
and size
arguments, where the class contain new setters:
Handler function returns success
status as the new argument
Example
$server = new \Yggverse\Nps\Server;
$server->start(
function (
bool $success,
string $content,
string $request,
string $connect
) {
printf(
'connection: %s request: %s',
$connect,
$request
);
if ($success)
{
var_dump(
$content
);
}
}
);
Full Changelog: 1.0.0...1.1.0
1.0.0
Initial stable release!
includes Server
class to build interactive applications
Example
$server = new \Yggverse\Nps\Server;
$server->start(
function (
string $content,
string $request,
string $connect
) {
printf(
'connection: %s request: %s',
$connect,
$request
);
var_dump(
$content
);
}
);
Full Changelog: https://github.com/YGGverse/nps-php/commits/1.0.0