webworker01 / komodophp

A library for working with Komodo addresses and keys and interfacing with full nodes and electrumx servers
https://packagist.org/packages/webworker01/komodophp
GNU General Public License v3.0
2 stars 2 forks source link

Connection to Electrumx #6

Closed melaxon closed 4 years ago

melaxon commented 4 years ago

By no means I cannot read from Electrumx.

I tried your package then I simplified the code as shown below, but I always receive "Connection reset by peer" I tried different hosts with the same result

$electrumhost = '213.109.162.82';
$electrumport = 50002;

$request = json_encode([
    'id' => 0,
    'method' => 'server.version',
    'params' => []
]);

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

if (socket_connect($socket, $electrumhost, $electrumport)) {

    $write = socket_write($socket, $request);
    if (!$write) {
        $errstr = "Failed to write. ".socket_strerror(socket_last_error());
        socket_close($socket);
        die($errstr);
    }

    $buf = socket_read($socket, 2048);

    if ($buf === '') 
    { 

        echo socket_strerror(socket_last_error());
        throw new \Exception('Connection reset by peer'); 
    } 
    else {
        var_dump($buf);
    }
} else {

    $errorMessage = socket_strerror(socket_last_error());
    throw new \Exception($errorMessage);
}

exit;
webworker01 commented 4 years ago

Your sample code does not look like it uses this library at all.

I noticed there are changes to electrumx since I originally wrote the electrum lib but the example below still works.

Seems that the library in it's current state is compatible with ElectrumX protocol prior to 1.3 so it will need to be updated.

<?php

require __DIR__ .'/vendor/autoload.php';

use webworker01\Komodo\Electrum;

$electrumhost = 'electrum1.cipig.net';
$electrumport = 10001;

$electrum = new Electrum();

$electrum->connect($electrumhost, $electrumport);
$serverVersion = $electrum->serverVersion();

echo '<pre>';
print_r($serverVersion);
echo '</pre>';

Details on what is required in #7 to get full functionality back.