473,396 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Simulate socket with files or stdin/stdout

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).

+------------+ stdout stdin +------------+ socket.write
| |------------------->| python- |----------------
| Simulation | | script |
| |<-------------------| |<---------------
+------------+ stdin stdout +------------+ socket.read
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
Now my question is, if someone has done something similar and can give me
some hints where to start, what to look for etc. Maybe someone even has
another idea how to solve this problem.

A skript that does something similar like "netcat" would be a good starting
point, since I'm really new to python programming.
The script should be usable on the MAC, PC and UNIX platform.
I'm very thankful for any input you can give me to find a good solution for
this.
Thanks

James
Jul 18 '05 #1
5 4692
[
Now my question is, if someone has done something similar and can give me
some hints where to start, what to look for etc. Maybe someone even has
another idea how to solve this problem.

A skript that does something similar like "netcat" would be a good starting
point, since I'm really new to python programming.

The script should be usable on the MAC, PC and UNIX platform.


On OSX and *nix, you'll have no problems using stdin and stdout for
communication with Python (I don't know about Modula2). In Windows,
you're going to have a few issues with stdin and stdout, but there are
workarounds using pywin32.

On OSX and *nix, you'll have no problems using files for communicating
with Python. In Windows, files can't be used as pipes like they are in
*nix, so this isn't even an option.

I'd say try for stdin/stdout, and check out the documentation on doing
stdin and stdout with pywin32.

- Josiah
Jul 18 '05 #2
In article <c4**********@newshispeed.ch>,
"Jean-Pierre Bergamin" <ja***@ractive.ch> wrote:
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).

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

On UNIX (and MacOS X), it may be easier than this already.
If your application will support the above configuration,
then it will almost for sure talk directly to the socket.
Try this:

import posix
import socket

def bind(port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', port))
s.listen(1)
c, a = s.accept()
print 'connection from', a
s.close()
return c

s = bind(2004)
fd = s.fileno()
posix.dup2(fd, 0)
posix.dup2(fd, 1)
posix.close(fd)
posix.execve('/usr/local/bin/similator', ['similator', '-flag1'],
posix.environ)
I've used posix.this and posix.that, instead of the politically
correct os.this and os.that, to emphasize the fact that this
is not portable to Windows.

If the above works, you'll be able to telnet directly to the
application host, port 2004, and interact with the application.
This obviously needs to be made a little more secure, but as
long as it's just authentication and authorization, that can
happen prior to the execve().

Donn Cave, do**@u.washington.edu
Jul 18 '05 #3
In article <do************************@nntp4.u.washington.edu >,
Donn Cave <do**@u.washington.edu> wrote:
In article <c4**********@newshispeed.ch>,
"Jean-Pierre Bergamin" <ja***@ractive.ch> wrote:
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).

Jul 18 '05 #4
Quoth cl****@lairds.com (Cameron Laird):
[... re invoking application with connected socket for unit 0 & 1 ...]
| I wonder how close the effect will be to recreation of inetd
| <URL: http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?inetd >.

Pretty close, given the root privilege to configure inetd and
no intent to add any authorization checks, logging or other
embellishments.

Donn Cave, do**@drizzle.com
Jul 18 '05 #5
Jean-Pierre Bergamin <ja***@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, <op**********@yahoo.ca>
Linux solution for data processing and document management.
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jas | last post by:
I have a basic client/server socket situation setup....where the server accepts a connection and then waits for commands. On the client side, I create a socket, connect to the server...then I...
0
by: Stefanos Harhalakis | last post by:
Hi there... I've seen in the mailing list archives that some people get this error message: FATAL: Socket command type E unknown I didn't find any solution so I'm sending this message... ...
9
by: Piotr Turkowski | last post by:
Hi, The code is here: http://free.ud.pl/~piotr/data/vigenere.zip Its my program for decrypting and encrypting text. Shot polish course: szyfrowanie (szyfruj) - encrypting (text i want to code...
2
by: chellappa | last post by:
Hi Every body!, i did a small Chat program in Linux C Socket Programm ... I am using stdout/stdin i did in single machinee i will work properly..but i want to run in differnet machine..i tried...
46
by: Sensei | last post by:
I was having an interesting discussion about the ANSI C and some ``weird inconsistencies'', or at least what at first sight can be seen as an imbalance. I hope someone can satisfy my curiosity. ...
0
by: carl.dhalluin | last post by:
Hi I want a simple way to interactively remote debug a running python script which has no tty terminal attached to it. The scripts are running standalone (i.e. they are automatically started and...
24
by: Bartc | last post by:
The stdin/stdout files of C seem to be always in Text mode. Is there any way of running a C program so that these (but especially stdout) are in Binary mode instead? (I'm in the process of...
4
by: pcfreak30 | last post by:
ok, i probably have not been registered here long, but i am no noob. I am very experienced in php, but the php cli is a bit of new territory for me. I am trying to create a simple little script...
0
by: Gabriel Genellina | last post by:
En Thu, 25 Sep 2008 09:49:31 -0300, Almar Klein <almar.klein@gmail.com> escribió: Use subprocess.PIPE Usually the tricky part is to figure out exactly whether there is more input or not. With...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.