glushkovds / php-smpp

WIP. Implementation SMPP v3.4 protocol. Includes sending and listening USSD.
MIT License
19 stars 11 forks source link

socket_close(): Argument #1 ($socket) must be of type Socket, null given #22

Closed momostafa closed 3 months ago

momostafa commented 3 months ago

Hi I am getting below error when I try to bind as receiver to receive DLR also no bind is not successful.

I hope someone can fix this bug.

Thank you for your time and support.

PHP 8.2.16

$host = $sending_server->api_link.':'.$sending_server->port;

    \PhpSmpp\Client::$sms_registered_delivery_flag = 0x01;
    \PhpSmpp\Client::$forceIpv4 = true;
    \PhpSmpp\Client::$nullTerminateOctetstrings = false;
    $service = new \PhpSmpp\Service\Listener([$host], $sending_server->username, $sending_server->password, \PhpSmpp\Client::BIND_MODE_RECEIVER, true);
    $service->listen(function (\PhpSmpp\Pdu\Sm $sm) {
        var_dump($sm->msgId);
        if ($sm instanceof \PhpSmpp\Pdu\DeliverReceiptSm) {
            var_dump($sm->state);
            var_dump($sm->state == \PhpSmpp\SMPP::STATE_DELIVERED);
            // do some job with delivery receipt
        } else {
            echo 'not receipt';
        }
    });

socket_close(): Argument #1 ($socket) must be of type Socket, null given

at vendor/glushkovds/php-smpp/src/Transport/SocketTransport.php:256 252▕ if ($this->debug) call_user_func($this->debugHandler, "Connecting to $ip:$port..."); 253▕ $r = @socket_connect($socket4, $ip, $port); 254▕ if ($r) { 255▕ if ($this->debug) call_user_func($this->debugHandler, "Connected to $ip:$port!"); ➜ 256▕ @socket_close($socket6); 257▕ $this->socket = $socket4; 258▕ return; 259▕ } elseif ($this->debug) { 260▕ call_user_func($this->debugHandler, "Socket connect to $ip:$port failed; " . socket_strerror(socket_last_error()));

momostafa commented 3 months ago

Thanks a lot for the fix