Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python inter-computer communication

Tags:

python

This whole topic is way out of my depth, so forgive my imprecise question, but I have two computers both connected to one LAN.

What I want is to be able to communicate one string between the two, by running a python script on the first (the host) where the string will originate, and a second on the client computer to retrieve the string.

What is the most efficient way for an inexperienced programmer like me to achieve this?

like image 954
matt1024 Avatar asked Dec 21 '25 08:12

matt1024


2 Answers

First, lets get the nomenclature straight. Usually the part that initiate the communication is the client, the parts that is waiting for a connection is a server, which then will receive the data from the client and generate a response. From your question, the "host" is the client and the "client" seems to be the server.

Then you have to decide how to transfer the data. You can use straight sockets, in which case you can use SocketServer, or you can rely on an existing protocol, like HTTP or XML-RPC, in which case you will find ready to use library packages with plenty of examples (e.g. xmlrpclib and SimpleXMLRPCServer)

like image 69
Dan Andreatta Avatar answered Dec 22 '25 20:12

Dan Andreatta


There are about a million ways.

If I were doing it, I'd use the SocketServer library, because it's not too insane, fairly well documented, and most importantly, I've used it before.

There are a couple of examples here: http://docs.python.org/library/socketserver.html#examples

like image 39
David Wolever Avatar answered Dec 22 '25 22:12

David Wolever



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!