Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Releases: YGGverse/nps-php

1.3.1

30 Apr 16:32
Compare
Choose a tag to compare

Correction release, includes:

Full Changelog: 1.3.0...1.3.1

1.3.0

25 Apr 13:24
Compare
Choose a tag to compare

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

$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

25 Apr 12:20
Compare
Choose a tag to compare

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

25 Apr 04:02
Compare
Choose a tag to compare

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

24 Apr 20:04
Compare
Choose a tag to compare

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