Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection to Electrumx #6

Closed
melaxon opened this issue Oct 23, 2019 · 1 comment
Closed

Connection to Electrumx #6

melaxon opened this issue Oct 23, 2019 · 1 comment

Comments

@melaxon
Copy link

melaxon commented Oct 23, 2019

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
Copy link
Owner

webworker01 commented Oct 24, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants