You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
2.1 KiB
118 lines
2.1 KiB
# nps-php 1.3.0 |
|
|
|
## New methods |
|
|
|
=> https://github.com/YGGverse/nps-php#serversetwelcome Server::setWelcome |
|
|
|
Define application logic on peer connection established |
|
|
|
``` php |
|
$server->setWelcome( |
|
function ( |
|
string $connect |
|
): ?string |
|
{ |
|
printf( |
|
"connected: %s\n\r", |
|
$connect |
|
); |
|
|
|
return sprintf( |
|
"welcome, %s\n\r", |
|
$connect |
|
); |
|
} |
|
); |
|
``` |
|
|
|
=> https://github.com/YGGverse/nps-php#servergetwelcome Server::getWelcome |
|
|
|
Get current Welcome function, null by default |
|
|
|
=> https://github.com/YGGverse/nps-php#serversetpending Server::setPending |
|
|
|
Define application logic on peer make initial request |
|
|
|
``` php |
|
$server->setPending( |
|
function ( |
|
string $request, |
|
string $connect |
|
): ?string |
|
{ |
|
printf( |
|
'connection: %s requested: %s', |
|
$connect, |
|
$request, |
|
); |
|
|
|
return sprintf( |
|
'received: %s', |
|
$request |
|
); |
|
} |
|
); |
|
``` |
|
|
|
=> https://github.com/YGGverse/nps-php#servergetpending Server::getPending |
|
|
|
Get current Pending function, null by default |
|
|
|
=> https://github.com/YGGverse/nps-php#serversethandler Server::setHandler |
|
|
|
Define basic application logic on complete packet received |
|
|
|
* could be also defined as Server::start argument |
|
|
|
``` php |
|
$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!'; |
|
} |
|
); |
|
``` |
|
|
|
=> https://github.com/YGGverse/nps-php#servergethandler Server::getHandler |
|
|
|
Get current Handler function, null by default |
|
|
|
## Example |
|
|
|
``` php |
|
$server->start(); |
|
``` |
|
|
|
``` |
|
> nc 127.0.0.1 1915 |
|
< welcome, 127.0.0.1:38028 |
|
> test |
|
< received: test |
|
> 1 |
|
> 2 |
|
> 3 |
|
> . |
|
< thank you! |
|
``` |
|
|
|
## Links |
|
|
|
=> https://github.com/YGGverse/nps-php/releases/tag/1.3.0 Download nps-php 1.3.0 |