tags:

views:

113

answers:

3

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?

+3  A: 

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

David Wolever
`SocketServer`'s one-thread-per-connection model doesn't scale well. I prefer Twisted for writing network apps.
Mike Graham
@Mike: True, Twisted does scale much, much better than SocketServer. But I believe simplicity of implementation trumps scalability for this particular question ;)
David Wolever
+3  A: 

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)

Dan Andreatta
A: 

File share and polling filesystem every minute. No joke. Of course, it depends on what are requirements for your applications and what lag is acceptable but in practice using file shares is quite common.

Yaroslav
The Problem screams use of TCP/UDP, why would he use file share and poling filesystem?
anijhaw
@anijhaw, OP does not stated too much requirements, for some applications throwing a file into shared folder is sufficient. And do not forget 'for an inexperienced programmer' clause.
Yaroslav
hahaha yup, that's how I implemented my first "network" application. +1 for good memories.
David Wolever
@David, thanks, colleague! :) We used such kind of "networking" for interoperability with legacy systems. Not sure that much people out there can develop TCP server on OS/390 :)
Yaroslav