473,688 Members | 3,192 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4719
[
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**********@n ewshispeed.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(s ocket.AF_INET, socket.SOCK_STR EAM)
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.washingt on.edu
Jul 18 '05 #3
In article <do************ ************@nn tp4.u.washingto n.edu>,
Donn Cave <do**@u.washing ton.edu> wrote:
In article <c4**********@n ewshispeed.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.c om (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.co m
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**********@y ahoo.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
9442
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 pass the socket to a class which just reads from the socket (in a thread). class Reader(Thread): def run(self): while 1:
0
1139
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... I had the same problem and after some debuging I've found that:
9
3721
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 -> (*(^%&^GHJBBVvkek) odszyfrowanie (deszyfrowanie) - decrypting ( *^BNHJ*&% - > secret text) obsluga plikow - using files
2
6990
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 ,but its faliure... try to modify this pgm run in differnt machine Server Program ============== #include <stdio.h> #include <sys/socket.h>
46
2161
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. The standard provides means to open files associating a /path/ with a /stream/. The standard does not provide any means to handle /directories/. There are three streams defined by the standard, stdin stdout stderr. Am I right? Now, what is the...
0
1332
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 have no terminal) and very infrequently come into error conditions which i want to understand and debug. The idea is that I do the debugging as shown below. Is that a good way of solving my problem? Do I need anything special
24
2794
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 wrapping a different language around C which doesn't want the concept of text and binary files. But if I output a string such as "ONE\nTWO\n", this will behave differently between stdout and a regular (binary) file. Examples on my OS:
4
2243
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 that will fetch a webpage and save it to a file. This is just for practice for the records. here is my code: <?php fwrite(STDOUT,"Created By Derrick Hammer\n");
0
1992
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 Python it's easy, use the ps1 prompt. --- begin --- import sys
0
8590
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8528
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8786
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7621
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5807
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4321
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2215
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.