Client/Server role reversal with SimpleXMLRPCServe

2019-08-12 09:05发布

问题:

I'm working on a project to expose a set of methods from various client machines to a server for the purpose of information gathering and automation. I'm using Python at the moment, and SimpleXMLRPCServer seems to work great on a local network, where I know the addresses of the client machines, and there's no NAT or firewall.

The problem is that the client/server model is backwards for what I want to do. Rather than have an RPC server running on the client machine, exposing a service to the software client, I'd like to have a server listening for connections from clients, which connect and expose the service to the server.

I'd thought about tunneling, remote port forwarding with SSH, or a VPN, but those options don't scale well, and introduce more overhead and complexity than I'd like.

I'm thinking I could write a server and client to reverse the model, but I don't want to reinvent the wheel if it already exists. It seems to me that this would be a common enough problem that there would be a solution for it already.

I'm also just cutting my teeth on Python and networked services, so it's possible I'm asking the wrong question entirely.

回答1:

What you want is probably WAMP routed RPC. It seems to address your issue and it's very convenient once you get used to it.

The idea is to put the WAMP router (let's say) in the cloud, and both RPC caller and RPC callee are clients with outbound connections to the router.

I was also using VPN for connecting IoT devices together through the internet, but switching to this router model really simplified things up and it scales pretty well.

By the way WAMP is implemented in different languages, including Python.



回答2:

Maybe Pyro can be of use? It allows for many forms of distributed computing in Python. You are not very clear in your requirements so it is hard to say if this might work for you, but I advise you to have a look at the documentation or the many examples of Pyro and see if there's something that matches what you want to do.

Pyro abstracts most of the networking intricacy away, you simply invoke a method on a (remote) python object.