2014-10-30 131 views
0

如何通過scgi接口直接與rtorrent對話?來自stdlib的Ruby XMLRPC客戶端只能通過HTTP協議進行通信,而rtorrent只能通過SCGI進行通信。Ruby SCGI/XMLRPC客戶端

回答

1

作爲起動:

#!ruby 

require "xmlrpc/client" 

class XMLRPC::RTorrent < XMLRPC::Client 
    def do_rpc(xml, async=false) 
    headers = { 
     'CONTENT_LENGTH' => xml.size, 
     'SCGI' => 1 
    } 

    header = "#{headers.to_a.flatten.join("\x00")}" 
    request = "#{header.size}:#{header},#{xml}" 

    TCPSocket.open(@host, @port) do |s| 
     s.write(request) 
     s.read.split(/\n\s*?\n/, 2)[1] 
    end 
    end 
end 

server = XMLRPC::RTorrent.new("127.0.0.1", '', 5000) 
p server.call("system.listMethods") 

它忽略異步,rtorrent的RPC是在端口5000

詳情:http://python.ca/scgi/protocol.txt