I'm struggling to make my own rpc client using nodejs based on this one: https://github.com/JohnDoee/deluge-client
The connection seems to work (if I turn off the daemon and run the code I clearly get a connection error) but when I send the request I get no answer (.on('data' function () {}) never fires).
On the other hand if I use deluge-client from JohnDoee everything works perfectly. His code is pretty clear but since I am a newbie in python maybe I missed something.
Here's my code
Code: Select all
var tls = require('tls')
var zlib = require('zlib')
var bencode = require('bencode')
var client = tls.connect({
port: 58846,
host: '127.0.0.1',
rejectUnauthorized: false,
checkServerIdentity: () => {
return undefined
},
secureContext: tls.createSecureContext({secureProtocol: 'SSLv23_method'}),
}, () => {
var login = send(1, 'daemon.login', ['USERNAME', 'PASSWORD'], {})
.then((buff) => {
client.write(buff)
var command = send(2, 'core.get_torrents_status', {}, ['name', 'progress', 'is_seed', 'paused', 'total_seeds', 'is_finished', 'state', 'files', 'file_progress'])
.then((buff2) => {
client.write(buff2)
})
})
})
.setEncoding('utf8')
// Add a 'data' event handler for the client socket
// data is what the server sent to this socket
.on('data', (data) => {
console.log('DATA: ' + data)
})
.on('end', () => {
console.log('Connection ended')
})
// Add a 'close' event handler for the client socket
.on('close', () => {
console.log('Connection closed')
})
.on('error', (error) => {
console.log('err ' + error)
})
var send = (request_id, method, args, kwargs) => {
return new Promise ((resolve, reject) => {
zlib.deflate(bencode.encode([request_id, method, args, kwargs]), (err, buffer) => {
return resolve(buffer)
})
})
}
Thanks in advance