如何在节点js中使rpc请求泛滥?

时间:2016-11-20 01:57:06

标签: javascript node.js rpc

过去几天我一直试图在节点上发出rpc请求,没有任何成功。我现在面临的问题是当我发送一个rpc请求时,例如

[1, "daemon.login", ["the_username", "the_password"]]

deluge没有回复任何东西,套接字只是保持打开状态。 我在冗长的模式中大肆挥霍,女巫根本没有帮助。唯一的信息泛滥给我的是客户端连接,它没有向我显示任何错误。那么我做错了什么?

我尝试过的步骤:

  1. Zlib压缩要发送的数据。
  2. Bencode对压缩数据进行编码。
  3. 发送到洪水。
  4. 我的代码:

    var tls = require('tls');
    var net = require('net');
    var zlib = require('zlib');
    var bencode = require('bencode');
    process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
    
    var toSend = '[1, "daemon.login", ["the_username", "the_password"]]';
    
    new Promise((done, fail) => {
        zlib.deflate(toSend, (err, buffer) => {
            return done(bencode.encode(buffer));
        });
    }).then(buff => {
        var client = tls.connect(58846, '192.168.0.22', function() {
            console.log('CONNECTED');
            // Write a message to the socket as soon as the client is connected, the server will receive it as message from the client 
            client.write(buff);
            console.log('Wroten');
        });
        // Add a 'data' event handler for the client socket
        // data is what the server sent to this socket
        client.on('data', function(data) {
            console.log('DATA: ' + data);
            // Close the client socket completely
            client.destroy();
        });
    
        // Add a 'close' event handler for the client socket
        client.on('close', function() {
            console.log('Connection closed');
        });
    });
    

    红宝石中的Deluge rpc库:https://github.com/t3hk0d3/deluge-rpc

    Deluge RPC文档:http://deluge.readthedocs.io/en/develop/core/rpc.html

0 个答案:

没有答案