Simulate socket with files or stdin/stdout

William Park opengeometry at yahoo.ca
Sun Apr 4 03:16:21 EDT 2004


Jean-Pierre Bergamin <james at ractive.ch> wrote:
> Dear python-Community
> 
> We are forced to use a quite old simulation software that's based on
> Modula-2. The idea is now to let this software "talk" to the outside world
> over a TCP/IP network.
> 
> Since the program has no possibility to use sockets or other mechanisms to
> send data over the network we have the idea to let python do the network
> part and let the simu software communicate with the python script in some
> other way:
> 
> One idea is to use stdout and stdin (but I'm not even sure if stdout/in are
> available in the simulation software).

This might be important, so you should find out... don't you think?

> 
> +------------+  stdout     stdin  +------------+  socket.write
> |            |------------------->|  python-   |----------------
> | Simulation |                    |  script    |
> |            |<-------------------|            |<---------------
> +------------+  stdin      stdout +------------+  socket.read

In Bash, Ksh,
    exec 3<>/dev/tcp/remote.host/4000 0<&3 1>&3
    simulation
    exec 3<&-
You can achieve the same thing, by running 'simulation' under 'inetd'.

> 
> 
> The other idea is to use files to communicate between the simultion program
> and the python script.
> 
> +------------+     +------+     +------------+  socket.write
> |            |---->|      |---->|  python-   |--------------
> | Simulation |     | File |     |  script    |
> |            |<----|      |<----|            |<-------------
> +------------+     +------+     +------------+  socket.read

Bad design.  Outgoing data from 'file' can go to 'simulation' or to
'python-script'.  How do you know what data should go to what direction?
That is, how does 'file' know whether 'simulation' or 'python-script' is
reading it?

If "input" and "output" files are different, then it's different story.

-- 
William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
Linux solution for data processing and document management.



More information about the Python-list mailing list