stratum mining protocol demo

使用 boost::asio 与f2pool建立TCP连接

#include 
#include 
using namespace boost::asio;
int main(int argc, char* argv[])
{
    // 所有asio类都需要io_service对象
    io_service iosev;
    // socket对象
    ip::tcp::socket socket(iosev);
    // 连接端点,这里使用了本机连接,可以修改IP地址测试远程连接
    ip::tcp::endpoint ep(ip::address_v4::from_string("106.15.161.68"), 8008);
    // 连接服务器
    boost::system::error_code ec;
    socket.connect(ep, ec);
    // 如果出错,打印出错信息
    if (ec)
    {
        std::cout << boost::system::system_error(ec).what() << std::endl;
        return -1;
    }
    // 接收数据
    char buf[1000];
    size_t len = socket.read_some(buffer(buf), ec);
    std::cout.write(buf, len);

    return 0;
}

VS下要预处理_WINSOCK_DEPRECATED_NO_WARNINGS
{"jsonrpc":"2.0","id":0,"result":["0x677e0a340ef76997badd6c9067ce40648f1c5bbd8f29bea0cf34bc58dbc02fa4","0xcb5d57db3888696bcf7c9b09b0c77c3ba41955b53950b8197064dc9df81cda49","0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff"],"error":null}

"0x677e0a340ef76997badd6c9067ce40648f1c5bbd8f29bea0cf34bc58dbc02fa4"表示当前job
"0xcb5d57db3888696bcf7c9b09b0c77c3ba41955b53950b8197064dc9df81cda49" 表示当前seed
"0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff" 表示当前难度

{"id": 1, "worker":"lrh", "method": "eth_submitLogin", "params":["0xff6514c44f4d3afeefdfca7913d33ec3a87747f3"]}\n"; 注册等级 m_worker user

回复:
{"jsonrpc":"2.0","id":1,"result":true,"error":null}

你可能感兴趣的:(c++,区块链,以太坊,ethereunm,区块链,jsonrpc,boost-asio)